English 中文(简体)
我如何着手创建两种铁路模型,这些模型需要同样的资源表名称,但数据不同?
原标题:How do I go about creating two Rails models that need the same resource table name but different data?

I m 建造铁路3.2号不动产管理(区)应用程序。 单位和财产都有设施。 财产可能具有诸如“公共汽车路线”和“眼镜”等设施,而一个单位可能拥有“空调”和“无障碍”等设施。 我最初指定了我的房地产福利资源表amenities和加入表amenities_properties。 然而,现在我开始为I m的部队建造我的设施表,不能确定我应如何命名。 我可以读到<代码>amenities_properties和amenities_units。 但是,然后我打电话到合并的表格amenities_properties_propertiesamenities_units_units? Seems weird to me.

最好有<代码>amenities。 表1. 哪类领域表明它是否属于单位或财产?

问题回答

我要讲多吗?

善意。

#There s not a grammatically good way to turn "amenity" into a polymorphic name so... 
belongs_to :amenitable, :polymorphic => true

财产、rb和单位。

has_many :amenities, :as => :amenitable

Making amenities polymorphic adds an amenitable_type and amenitable_id column to the amenities table.

因此,当你创造新的活力时,将<代码>menitable_type 至 unit property (取决于您的模版名称)和amenitable_id至其所属单位或财产。





相关问题
Codeigniter WHERE on "AS" field

I have a query where I need to modify the selected data and I want to limit my results of that data. For instance: SELECT table_id, radians( 25 ) AS rad FROM test_table WHERE rad < 5 ORDER BY rad ...

Problem find joined table in rails

I have model represent association rule (Body => Head) def Item has_many :heads has_many :bodies ... end def Rule has_many :heads has_many :bodies ... end def Body belongs_to :item belongs_to :rule ...

FreeTDS Bad token from the server (SQL Server)

Today we had a lot more activity than normal between our Ruby on Rails application and our remote legacy SQL Server 2005 database, and we started getting the error below intermittently. What is is? ...

Castle ActiveRecord: one-to-one

While playing around with one-to-one associations in castle activerecord I stumbled upon the following problem: I m trying to model a one-to-one relationship (user-userprofile in this case). I ...

Sending email updates: model or observer?

I have an Event model, which stores an event feed for each user. I also need to email the updates to users which have enabled email notifications in their profile. From an architectural point of view,...

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

热门标签