This is a continuation of this question: Original Question (SO)
The answer to this question included the following set of models:
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 <% for friendship in @user.friendships %> <%= friendship.status %> <%= friendship.friend.firstname %> <% end %>
This works great if I say I have a user and I want to get all βfriendshipsβ for which his or her identifier is: user_id FK on the friendship model. BUT when I run something like
@user.friendships.friends
I would like for him to return all user records for which this User is either a user or a friend: friendship - in other words, to return all the friendships in which this user is involved.
Hope this makes sense. I am still new to rails and hope there is a way to do this elegantly without doing just a standard reference table or providing custom SQL.
Thanks!
Tom
ruby ruby-on-rails
cakeforcerberus
source share