Add belongs_to :through
Reported by Dan Kubb | June 27th, 2008 @ 09:40 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 Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
