4

Rails4.0.0.betaを使用すると次のエラーが発生します。

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

Rails 3.2.xを使用しても、例外は発生しません。

Rails3.2.13とRails4.0.0.betaの両方にRuby1.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

has_manyRails 4対応コードを使用して同じ機能を実現する方法を知りたいですか?

PS私はまだ古いスタイルの構文を使用していること、および条件ハッシュにprocまたはlambdaが必要であることを認識していますが、これらによってundefined method例外が発生することはありません。

4

1 に答える 1

7

私は犯人を見つけました。それは、 -go図の代わりにperfectline/validates_existence非推奨にデフォルト設定されている宝石です! 修正を含むプル リクエストを送信しました ( https://github.com/perfectline/validates_existence/pull/20 )。私を正しい方向に向けてくれてありがとう@Beerlington。primary_key_nameforeign_keyActiveRecord::VERSION::MINOR >= 1

于 2013-03-12T15:01:12.980 に答える