Need help with find

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

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.

On 2 April 2010 15:21, RVRoadie [email protected] 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 @club

What are the relationships between the models (has_many, belongs_to and
so on)?

Colin

Club has many Members
Person has many Members
Members belong to Club, Person

On 3 April 2010 15:32, RVRoadie [email protected] wrote:

Club has many Members
Person has many Members

That’s novel.
Possibly memberships would be a better name, or am I misunderstanding
what this table is for?

Members belong to Club, Person

You 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 [email protected] 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

In 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 @club

If 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.