Ah the part about other memberships wasn't clear. The problem is that
memberships is already joined into the query so it needs to be aliased and
then another join performed. I'd do it the way you are doing it now, really.
If you want to make it 1 query you could use @user.board_ids.to_sql to embed
it in the conditions as a sub-query... maybe.

Bo
[image: Bodaniel Jeanes]

*Bodaniel Jeanes* [image: LinkedIn]
<http://www.linkedin.com/in/bjeanes>[image:
Twitter]  <http://twitter.com/bjeanes>[image: Tungle.me]
<http://tungle.me/bjeanes>[image:
Blog] <http://bjeanes.com>
Whttp://bjeanes.com [email protected]+61412639224
[image: Google Talk] [image: MSN] [image: Google Wave] [email protected] [image:
Skype][image: AIM] bojeanes




On Thu, Oct 21, 2010 at 7:06 AM, Ben Hoskings <[email protected]> wrote:

> 2010/10/21 Bodaniel Jeanes <[email protected]>
>
> Ben,
>>
>> I assume you are doing has_many :boards, through => :memberships?
>>
>> Isn't this just @user.memberships? Or are users associated with boards in
>> a different wy?
>>
>
> Yep, User -> Membership and Board -> Membership are both standard has_many
> relationships.
>
> So, current_user.memberships is all this user's memberships. I'm after all
> the memberships on all the boards this user is a member of. That is, for
> every membership that Membership.where(:user_id => current_user.id)
> returns, I want to also include every other membership to the corresponding
> board.
>
> (The purpose of this is a readable_by filter for Membership: it's all the
> memberships that this user can know exist. That is, a given user can see all
> the memberships on all the boards they're a member of.)
>
> (If there's a better way to do what I'm trying to do then I'd be keen to
> hear that too.)
>
> —ben_h
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby or Rails Oceania" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rails-oceania%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rails-oceania?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" 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/rails-oceania?hl=en.

Reply via email to