Kad Kerforn
2007-Jan-03 16:22 UTC
ActiveRecord - has_many :through w auto referenced table
Happy New Year to all rubyist and railist ... only 3 days in new yaer and already a question .... I am using a ''User'' table which is self-referenced via a joint Credential table.. according to the follwoing declarations : class User < ActiveRecord::Base has_many :credentials, :dependent => true has_many :referees, :through => :credentials has_many :referenced_users, :through => :credentials class Credential < ActiveRecord::Base belongs_to :referee, :class_name => ''User'', :foreign_key => ''referee_id'' belongs_to :referenced_user, :class_name => ''User'' , :foreign_key => ''referenced_user_id'' In my controller, when I try to get all referees from a user : @contacts = current_user. referees # current_user.id = 22 I get an error : Mysql::Error: Unknown column ''credentials.user_id'' in ''where clause'': SELECT users.* FROM users INNER JOIN credentials ON users.id credentials.referee_id WHERE (credentials.user_id = 22) what''s missing in the User declarations ? thanks for your lights ! kad -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---