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-/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''m also trying to find a way of doing this if anybody has any suggestions; will report back if I find a way of doing it. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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 <pankajbhageria-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> [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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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)
Using :conditions will work but the problem is that you''ve just introduced duplication between the conditions and the named_scope. Anyway, here''s my initial pass at trying to solve this: https://gist.github.com/82c50486bc38b7d7c880 It only works for conditions at the moment which was enough for me; please do fork the gist and hack away! Cheers Luke --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---