This seems so easy but I keep hitting a brick wall on this.

I have this modeling:

[code]
 class User < ActiveRecord::Base
   has_many :friendships
   has_many :friends, :through => :friendships #...
 end

 class Friendship < ActiveRecord::Base
   belongs_to :user
   belongs_to :friend, :class_name => 'User', :foreign_key =>
'friend_id'
end
[/code]

I have these 2 records in the friends table

user_id, friend_id
   3         4
   3         5

Now when I try to select all friends that belong to User of id 3, using
this select I get one record instead of 2:

@users = User.find:all, :include=>[:friendships],
:conditions=>["friendships.user_id=?",3])

Any ideas how I can model this and query this correctly to get both
records belonging to User 3?

Thanks a whole lot!

Clem
-- 
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to