Re: [Rails] Nested has_many queries in AR?
On 19 October 2010 21:06, Greg Willits <lists@ruby-forum.com> wrote:
> Aaa has_many Bbb and Bbb has_many Ccc. There is no :through involved.
> Ccc table does not have a FK back to Aaa. (Legacy schema.)
I do not understand what you mean by 'there is no through involved'.
In the situation described you may say
Aaa :has_many :cccs, :through => :bbbs
then you may use aaa.cccs
Colin
>
> An instance of aaa can easily query with aaa.bbb.find (or .paginate),
> but aaa.bbb.ccc.paginate() doesn't work because Aaa has no knowledge of
> Ccc.
>
> What's the idiomatic way of dealing with this? Loop through
> aaa.bbb.paginate results and generate N queries for Ccc and flatten the
> array? Seems too brutish.
>
> Not finding great answers via Google, everyone seems to do has_many
> :through, and that just doesn't apply here.
>
> Oh -- Rails 3, but using WillPaginate. If there's a paginate()
> compatible way to do this, I need that. Second choice would be to use an
> AR3 way to do it that won't work with paginate(), and I can hack my own
> pagination.
>
> TIA for pointers.
>
> -- gw
>
> --
> Posted via http://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 rubyonrails-talk@googlegroups.com.
> 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.
>
>
--
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@googlegroups.com.
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home