を逆協会を見つけることができなかった私は、次のモデルがあります:がレール3にhas_manyのため
class Business < ActiveRecord::Base
has_many :customers, :inverse_of => :business
has_many :payments, :inverse_of => :business
end
class Customer < ActiveRecord::Base
belongs_to :business, :inverse_of => :customer
has_many :payments, :inverse_of => :customer
end
class Payment < ActiveRecord::Base
belongs_to :customer, :inverse_of => :payment
belongs_to :business, :inverse_of => :payment
end
は細かいbusiness.customers
作品を行います。しかし、私がしたときbusiness.payments
私はエラーを受け取ります:Could not find the inverse association for business (:payment in Business)
。
私はなぜそう思っています。私は両方の方法で同じ正確な関係を持っています。私のschema.dbもうまく見えます。ここで何が問題になるのでしょうか?
EDIT 私はhas_many :payments
ためinverse_of => :business
を削除すると、それが動作します。なぜこれが起こるのですか?それは、支払いが顧客およびビジネスに属することに関連していますか(それは本当に重要ではないでしょうか?) belongs_to
のもう一方の側は、複数の関係を規定has_many
、ある
belongs_to :customer, :inverse_of => :payment
belongs_to :business, :inverse_of => :payment
:
belongs_to :business, :inverse_of => :customer
とで:
があなたをしたする必要がありますが、お支払いにあなたは
belongs_to :business, :inverse_of => :payment
を使用
ビジネスモデルに
has_many :payments, :inverse_of => :business
を宣言しました適用するDB内の関連付けを更新するための適切なレーキコマンド? – wandarkaf@ wandarkafはい、db:migrate。最初のマイグレーションをしたときからの団体がそこにありました。上記の編集をご覧ください。 – darksky