「has_many :through」を使用して次のモデルを作成することを考えています。
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
たとえば、最初に「rails generate model Contract authnum:string, client_id:integer, st_date:date, end_date:date」でモデルを作成しますか? 次に、移行の前にすべての関連付けを入力しますか?.
また、 has_many :through 関連付けを使用すると、すべての結合テーブルがレールによって自動的に作成されることを理解しています。それはいつ起こりますか?
最後に、** で示されているように、この属性をコードラインに含めることはできますか? また、この属性を結合テーブルに追加するために、「rails generate migration add_units_alloc_to_codelines units_alloc:number」を作成する必要がありますか? また、数値が小数点以下2桁であると宣言する方法も疑問に思っていましたか?
お時間とご都合がよろしければ、私のデータベースのデザイン案についてコメントいただけませんか?
ありがとう。