Forum: Ruby on Rails Nested One-To-Many ActiveRecord Question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Iain Delaney (Guest)
on 2006-03-21 21:29
(Received via mailing list)
I have a set of one-to-many relationships, nested 4 deep. In other
  table_A has_many table_B,
  table_B belongs_to table_A, has_many table C,
  table_C belongs_to table_B, has_many table D,
  table_D belongs_to table_C

Now, I want to to find on table_A, based on criteria in table_D, and
I want to paginate it. And I need fields from all four tables in the
result set.
Does anyone know how I can go about this?

I know that this will work:

@table_A = Table_A .find_by_sql ("select * from table_A, table_B,
table_C, table_D where ... ")
using joins and filters in the SQL statement, but I can't really see
how use this with the Paginator, and it also seems really un-Rails-
like. The find_by_sql is returning a ton of stuff I don't need, and
the SQL is server-specific.

Thanks in advance for your help,

This topic is locked and can not be replied to.