在rails应用程序中启用2个不同的模型与同一个表交谈 [英] Enabling 2 different models in a rails app talk to the same table
本文介绍了在rails应用程序中启用2个不同的模型与同一个表交谈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一些集成问题。我有2个模型,需要映射,以使他们能够谈论同一个表。因此,一个模型有一些属性映射到表中的相应列,同样对于其他模型。
I'm having a few integration issues. I have 2 models which need to be mapped so as to enable them to talk to the same table. So one model has a few attributes that are mapped to the corresponding columns in the table and likewise for the other model.
我听说过别名,一种可以使用的技术。帮助将不胜感激。谢谢 !
I've heard of aliasing, a technique that can be used. Help would be appreciated. Thanks !
推荐答案
您创建两个模型并定义相同的table_name
You create your two model and define the same table_name
class ProjectComplete < ActiveRecord::Base
set_table_name "projects"
end
class ProjectLittle < ActiveRecord::Base
set_table_name "projects"
end
这篇关于在rails应用程序中启用2个不同的模型与同一个表交谈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文