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_many
Rails 4対応コードを使用して同じ機能を実現する方法を知りたいですか?
PS私はまだ古いスタイルの構文を使用していること、および条件ハッシュにprocまたはlambdaが必要であることを認識していますが、これらによってundefined method
例外が発生することはありません。