Rails 4:未定义的方法`primary_key_name’

我使用Rails 4.0.0.beta收到以下错误:

NoMethodError: undefined method `primary_key_name' for #<ActiveRecord::Reflection::AssociationReflection 

使用Rails 3.2.x时,我没有得到exception。

我在Rails 3.2.13和Rails 4.0.0.beta上使用Ruby 1.9.3-p194。

问题源于以下has_many声明:

 class Store  :relationships, :source => :user, :conditions => { :relationships => { :description => "Customer" } } do def < "Customer", :user => user) end end end 

我有以下支持课程:

 class User  :relationship end class Relationship < ActiveRecord::Base belongs_to :store belongs_to :user end 

我想知道如何使用Rails 4友好代码实现相同的has_manyfunction?

PS我知道我仍然使用旧式语法,条件哈希现在需要proc或lambda,但这些不应该导致undefined methodexception。

我找到了罪魁祸首,它是perfectline/validates_existence gem,当ActiveRecord::VERSION::MINOR >= 1时,默认为不推荐使用的primary_key_name而不是foreign_key – 去图! 我已经提交了一个带有修复程序的拉取请求( https://github.com/perfectline/validates_existence/pull/20 )。 谢谢你指出我正确的方向@Beerlington。