On May 1, 5:55 pm, Stephen Fagan <[email protected]>
wrote:
> I want to link up 3 tables to list all members of a particular group. My
> code (which is wrong) looks like this:
>
> @group_members = Membership.find( :all,
>                                   :joins => ['FROM memberships INNER
> JOIN groups ON memberships.group_id= group.id' + 'INNER JOIN users ON
> memberships.user_id=users.id'])
>

this form of sql assumes that you are giving it a list of associaton
names, ie

Membership.find(:all, :joins => [:groups, :users]) looks like it would
do what you are trying to do.

The other form involves sql fragments, in which case you must provide
one such fragment, not an array ie


@group_members = Membership.find( :all,
                                   :joins => 'INNER JOIN groups ON
memberships.group_id= group.id INNER JOIN users ON
memberships.user_id=users.id')


Fred
> This gives me an "association name not found" error. From my log file
> the sql string is as follows:
>
> 'FROM memberships INNER JOIN groups ON memberships.group_id=
> group.idINNER JOIN users ON memberships.user_id=users.id'
>
> Can anyone please let me know where I'm going wrong - SQL is not my
> forté :@/
>
> Thanks
>
> Steve
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to