Hi Pankaj, I don't know how to do this with named_scope, but maybe you'll like this:
class User has_many :pending_friends, :through => :friendship, :source => :friend, :conditions => {'friendships.is_accepted' => 'true'} end However, you can't do sth. like @user.pending_friends << @friend anymore in this way. See: http://rails.lighthouseapp.com/projects/8994/tickets/718-has_many-method-doesn-t-handle-conditions Jan * pankaj <pankajbhage...@gmail.com> [2009-02-20 04:30:09 -0800]: > > class User > > has_many :friendships > has_many :friends, :through => :friendship > end > > > class Friendship > belongs_to :user > belongs_to :friend, :class_name => 'User' > named_scope :accepted, :conditons => "is_accepted = true" > named_scope :pending, :conditons => "is_accepted = false" > end > > Here in the User class, i want to write > has_many :pending_friends, through a named scope friendships accepted > has_many:accepted_friends through a named scope pending > > Please help, > Regards, > Pankaj > --~--~---------~--~----~------------~-------~--~----~ > 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@googlegroups.com > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en > -~----------~----~----~----~------~----~------~--~--- -- jan=callcc{|jan|jan};jan.call(jan)
pgpIJ5P755R4M.pgp
Description: PGP signature