I have a self-referential association using the following two models: class User < ActiveRecord::Base has_many :incoming_friendships, :foreign_key => :user1_id, :class_name => :friendship has_many :outgoing_friendships, :foreign_key => :user2_id, :class_name => :friendship has_many :incoming_friends, :through => :outgoing_friendships has_many :outgoing_friends, :through => :incoming_friendships #... end class Friendship < ActiveRecord::Base belongs_to :user1, :class_name => :user, :foreign_key => :user1_id belongs_to :user2, :class_name => :user, :foreign_key => :user2_id end In theory (according to josh; http://blog.hasmanythrough.com/2006/4/21/self-referential-through) this should work fine. However, I''m having some trouble... When using the console, I try the command "User.find(1).incoming_friends". This results in a TypeError;>> User.find(1).incoming_friendsTypeError: can''t convert Symbol into String from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/base.rb:1087:in `type_name_with_module'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/base.rb:1356:in `compute_type'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/reflection.rb:125:in `send'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/reflection.rb:125:in `klass'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/reflection.rb:177:in `source_reflection'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/reflection.rb:177:in `collect'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/reflection.rb:177:in `source_reflection'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/reflection.rb:186:in `check_validity!'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/associations/has_many_through_association.rb:6:in `initialize'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/associations.rb:934:in `new'' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/ lib/active_record/associations.rb:934:in `incoming_friends'' from (irb):1 If anyone has a clue what I might be doing wrong, I''d greatly appreciate some help! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I figured it out with help from somewhere else...for those who might be interested the solution was to name classnames and column names with strings, not symbols. It puzzles me why, but at least that solved my problem. So the two finished models looks like this: class User < ActiveRecord::Base #Friendship relations has_many :incoming_friendships, :class_name => "Friendship", :foreign_key => "user1_id" has_many :outgoing_friendships, :class_name => "Friendship", :foreign_key => "user2_id" has_many :incoming_friends, :through => :outgoing_friendships, :source => :user1 has_many :outgoing_friends, :through => :incoming_friendships, :source => :user2 def friends incoming_friends.find(:all, :conditions => :confirmed != nil) + outgoing_friends.find(:all, :conditions => :confirmed != nil) end end class Friendship < ActiveRecord::Base belongs_to :user1, :class_name => "User", :foreign_key => "user1_id" belongs_to :user2, :class_name => "User", :foreign_key => "user2_id" end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---