This project is archived and is in readonly mode.
Support join based eagerloading of has_one through associations
Reported by Frederick Cheung | August 25th, 2008 @ 11:23 PM | in 2.x
has_one :through currently only supports eager loading via the newer preload scheme. This patch enables use of the previous join based scheme
Comments and changes to this ticket
-
Frederick Cheung August 25th, 2008 @ 11:34 PM
- no changes were found...
-
Tarmo Tänav August 26th, 2008 @ 01:16 AM
Added another patch on top of this one that fixes join-based eager loading of has_one associations with more than one matching record and an order.
-
Repository August 26th, 2008 @ 05:27 AM
- State changed from new to resolved
(from [6ae0a0557d5e2859e359275b5feebb7e3c13271c]) Load the first and not the last has_one result when doing join-based eager loading
This matters when the has_one is defined with an order in which case there is an expectation that the first one will be loaded.
[#904 state:resolved]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
Repository August 26th, 2008 @ 05:27 AM
(from [a445cdd8840c4e99c40c6d5b15ab380d39a56be3]) Load the first and not the last has_one result when doing join-based eager loading
This matters when the has_one is defined with an order in which case there is an expectation that the first one will be loaded.
[#904 state:resolved]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
Fotos Georgiadis September 14th, 2010 @ 09:05 AM
- Importance changed from to
Hi,
we just got bitten by the change done in http://github.com/rails/rails/commit/a445cdd
This breaks nested has_many associations as illustrated in ticket #5623.
As we understand it this patch was added to cover cases like this (taken from post.rb test model):
has_one :last_comment, :class_name => 'Comment', :order => 'id desc'
Well, this seems like an abuse of the has_one association and can definitely be written in better ways, which is something we should be promoting, like:
has_many :comments do def last find(:first, :order => "id DESC") end end
One could argue that providing an :order option for has_one relations doesn't make any sense at all. A has_one denotes that there is only one record on the other side of the association and "ordering" it doesn't look right. Perhaps tho it serves another purpose we seem to neglect...
We propose a reversal of the patch done in http://github.com/rails/rails/commit/a445cdd, since it breaks legitimate use cases (in a way that it's easy to miss it returns the wrong results), while there's still a way to write the above scenario in a clean, workable way.
Any insight on this issue is mostly welcomed.
-fotos
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 904 Support join based eagerloading of has_one through associations [#904 state:resolved]
- 904 Support join based eagerloading of has_one through associations [#904 state:resolved]
- 5623 Eager loading a nested association with conditions or order eager loads the wrong associated records This line was committed in: http://github.com/rails/rails...