ruby-on-rails – Rails 4:未定义的方法`primary_key_name’

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

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

使用Rails 3.2.x时,我没有得到异常.

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

问题源于以下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,但这些不应该导致未定义的方法异常.

解决方法

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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...