I get the following error using Rails 4.0.0.beta:
NoMethodError: undefined method `primary_key_name' for #<ActiveRecord::Reflection::AssociationReflection
I get no exception when using Rails 3.2.x.
I am using Ruby 1.9.3-p194 for Rails 3.2.13 and Rails 4.0.0.beta.
The problem is with the following has_many statement:
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
I have the following supporting classes:
class User < ActiveRecord::Base has_one :relationship has_one :store, :through => :relationship end class Relationship < ActiveRecord::Base belongs_to :store belongs_to :user end
I would like to know how I can achieve the same has_many functionality using Rails 4-friendly code?
PS I know that I still use the old-style syntax and that the condition hash now requires proc or lambda, but they should not throw an undefined method exception.
ruby-on-rails ruby-on-rails-4 rails-activerecord
Jurgen Mar 12 '13 at 11:51 2013-03-12 11:51
source share