#423 ✓not-applicable
Dan Kubb (dkubb)

Add belongs_to :through

Reported by Dan Kubb (dkubb) | June 27th, 2008 @ 09:46 PM

I'd like to see a belongs_to :through option added, where you could do stuff like this:

belongs_to :order
belongs_to :customer, :through => :order

The brute force approach could be to simply go: self.order.customer under the hood, which will perform two queries when self.customer is called.

A more elegant approach would be when self.customer is called to make a query that links the Order and Customer models (since self already knows the order_id) and retrieves the Customer in a single query.

It should also be possible to layer :through statements on top of each other any number of levels deep (the same as has :through is supposed to work), eg:

belongs_to :order
belongs_to :customer, :through => :order
belongs_to :affiliate, :through => :customer

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket