を通じて私が使用して、次のモデルを作成することを考えています「にhas_manyの:を通じて」:文字列、CLIENT_ID:整数、は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を生成」でモデルを作成してくださいst_date:date、end_date:date 'などです。 その後、移行の前にすべての関連付けを記入してください。
また、私の理解では、has_many:throughアソシエーションを使用すると、すべての結合テーブルが自動的に作成されます。それはいつですか?
最後に、**で示されているように、この属性をコードラインに含めることができますか?この属性を結合テーブルに追加するには、 'rails generate migration add_units_alloc_to_codelines units_alloc:number'を作成しますか?私はまた、数字を小数点以下2桁まで宣言する方法も不思議でした。
時間と傾きがある場合は、私のデータベースの提案デザインにコメントしてください。
ありがとうございました。レールは自動的にそのモデルを構築していないので、あなたはそれを自分で構築し、他の二つのモデルの外部キーを参照する、あなたは他の二つの間の接続を行う第3のモデルを使用しhas_many :through
を使用して
ありがとう@Andrei S、だから、私はコードラインとクライアントラインモデルを作成し、contract_idとclient_idを参照する必要がありますか? – thomasvermaak