Neal L wrote:
I’m trying to find a simple way to reference all of the objects that
belong to their parent’s parent. In other words:
Clients --> Orders --> LineItems
How do I get all of a client’s lineitems in one array (i.e.,
I’m assuming LineItem belongs_to :order and Order belongs_to :client.
If you are using Edge Rails, you can set this up as a
has_many…:through association, then you just say
client.orders.line_items and let Rails do the work for you.
If you’re on 1.0, you can do this with some custom SQL:
in class LineItem…
self.find_by_sql(‘SELECT DISTINCT li.* FROM clients c, orders o,
line_items li WHERE c.id = :client_id AND o.client_id = c.id AND
li.order_id = o.id’, :client_id => client.id)