Kind of new at this and have been unable to find an example of what I want to do. I have three models, people, clubs and members. @members = @club.members.all --> finds all club members How do I write a find of all people that are not members of @club Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Finally figured out something that worked. @club = Club.find(params[:club_id]) ids = @club.members.connection.select_values(''SELECT person_id FROM members'') @people = Person.all(:order => ''name_sort'', :conditions => ["id NOT IN (?)", ids]) Any comments or better methods. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 April 2010 15:21, RVRoadie <rvroadie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Kind of new at this and have been unable to find an example of what I > want to do. > > I have three models, people, clubs and members. > > @members = @club.members.all --> finds all club members > > How do I write a find of all people that are not members of @clubWhat are the relationships between the models (has_many, belongs_to and so on)? Colin> > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Club has many Members Person has many Members Members belong to Club, Person> > What are the relationships between the models (has_many, belongs_to and so on)? > > Colin >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 April 2010 15:32, RVRoadie <rvroadie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Club has many Members > Person has many MembersThat''s novel. Possibly memberships would be a better name, or am I misunderstanding what this table is for?> Members belong to Club, PersonYou seem to have snipped the original question. I will have to get it back from the earlier post. On 2 April 2010 15:21, RVRoadie <rvroadie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Kind of new at this and have been unable to find an example of what I > want to do. > > I have three models, people, clubs and members. > > @members = @club.members.all --> finds all club membersIn fact you can just use @club.members to give you all the members of @club. Are you not more likely to want all the people that are members of the club though? If you also say club has_many people through memberships then you can also @club.people to give you all the actual people.> > How do I write a find of all people that are not members of @clubIf you further have person has_many clubs through memberships then person.clubs will give you all his clubs and to get the people who are not members of @club you can do something like person.find( :all, :include => :clubs, :conditions => [''club.id <> ?'', @club.id] ) That might not be quite right, but something like that.> > >> >> What are the relationships between the models (has_many, belongs_to and so on)? >> >> Colin >> > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.