Re: TypeError on sef-referential association

digitalex
2007-07-13T08:58:08Z

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
-~----------~----~----~----~------~----~------~--~---