我想用创建以下车型“的has_many:通过”:实现一个的has_many:通过
class Contract < AR::Base
has_many :clientlines
has_many :codelines
has_many :clients, :through => :clientlines
has_many :codes, :through => :codelines
end
class clientlines < AR::Base
belongs_to :contract
belongs_to :client
end
class Client < AR::Base
has_many :clientlines
has_many :contracts, :through => :clientlines
end
class codeline < AR::Base
belongs_to :contract
belongs_to :code
units_alloc -------**I would like to add this attribute after this intermediate
end has been created?
class Code < AR::Base
has_many :codelines
has_many :contracts, :through => :codelines
end
不要我先建立模型的轨道产生合同范本authnum:字符串,CLIENT_ID:整数,例如,“st_date:date,end_date:date”。 然后在迁移之前填写所有关联?
另外,我的理解是,所有的连接表是在使用has_many:through关联时由rails自动创建的。这是什么时候发生的?
最后,如**所示,我可以在代码行中使用此属性吗?是否创建'rails generate migration add_units_alloc_to_codelines units_alloc:number'以将此属性添加到连接表中?我还想知道如何将数字声明为小数点后两位?
如果您有时间和倾向,请您评论我为我的数据库提出的设计?
谢谢。
谢谢@Andrei S,所以我需要创建代码行和客户端模型,并引用contract_id和client_id? – thomasvermaak 2012-02-24 20:14:03