Assuming the user id comes from params, I''m thinking:
@user = User.find(params[:id], :include {subscriptions => :magazines})
On Jun 27, 8:07 pm, Marcelo Barbudas
<nos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> I have the regular has_many through setup:
> user:
> has_many subscriptions
> has_many magazines, through subscriptions
>
> subscription holds important data like expiration date and other
> pieces of information.
>
> I am looking to display the subscription information without having to
> resort to an extra query for each magazine.
>
> For my particular case I have a RESTful magazines controller where I
> run :
> @magazines = current_user.magazines. In my view I need to display the
> subscription data for each magazine.
>
> Doing something like @magazine.subscriptions would return all
> subscriptions and @magazine.subscriptions.find(:first, :conditions =>
> [ ''magazine_id = xx AND user_id = xxx'' ]) would have to
make a query
> for each item.
>
> How would you do it?
>
> --
> M
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---