我在使用Rails 4.0.0.beta时收到以下错误:
NoMethodError: undefined method `primary_key_name' for #<ActiveRecord::Reflection::AssociationReflection在使用Rails 3.2.x时,我没有得到异常。
我将Ruby 1.9.3-p194用于Rails 3.2.13和Rails 4.0.0.beta。
该问题源于以下has_many语句:
class Store < ActiveRecord::Base
has_many :relationships
has_many :customers, :through => :relationships, :source => :user,
:conditions => { :relationships => { :description => "Customer" } } do
def <<(user)
proxy_association.owner.relationships.create(:description => "Customer", :user => user)
end
end
end我有以下支持类:
class User < ActiveRecord::Base
has_one :relationship
has_one :store, :through => :relationship
end
class Relationship < ActiveRecord::Base
belongs_to :store
belongs_to :user
end我想知道如何使用Rails 4友好的代码实现相同的has_many功能?
附注:我知道我仍然在使用老式的语法,条件散列现在需要一个proc或lambda,但这些不应该导致undefined method异常。
发布于 2013-03-12 23:01:13
我找到了罪魁祸首,这是perfectline/validates_existence gem,当ActiveRecord::VERSION::MINOR >= 1 - go出现时,它默认使用不推荐使用的primary_key_name而不是foreign_key!我已经提交了一个带有修复的拉取请求(https://github.com/perfectline/validates_existence/pull/20)。感谢您为我指明正确的方向@Beerlington。
https://stackoverflow.com/questions/15360418
复制相似问题