我有以下型號:找不到逆協會的has_many對Rails 3
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也很好看。這裏可能是什麼問題?
編輯 當我刪除了inverse_of => :business
爲has_many :payments
,它的工作原理。爲什麼會發生?這與支付是否屬於客戶和業務有關(它應該不重要,對嗎?)?
沒有你應用正確的rake命令用於更新數據庫中的關聯? – wandarkaf
@wandarkaf是的,db:migrate。這些協會從我第一次遷移時就在那裏。請參閱上面的編輯。 – darksky