This project is archived and is in readonly mode.
:uniq option doesn't work with has_many :through and eager loading
Reported by DerGuteMoritz | April 7th, 2009 @ 08:41 PM | in 3.x
class LineItem
belongs_to :event
end
class Order
has_many :line_items
has_many :events, :through => :line_items, :uniq => true
end
Order.first(:joins => :line_items).events # => expected result
Order.first(:joins => :line_items).event_ids # => contains duplicate IDs
Order.first(:include => :line_items).events # => contains duplicates
Order.first(:include => :line_items).event_ids # => contains duplicate IDs
Comments and changes to this ticket
-
Jon Leighton December 16th, 2010 @ 12:51 AM
- Assigned user set to Aaron Patterson
- Tag changed from activerecord, eager_loading, has_many_through, uniq to activerecord, eager_loading, has_many_through, patch, uniq
- Importance changed from to
Here is a patch which fixes this, with tests.
-
Repository December 16th, 2010 @ 01:49 AM
- State changed from new to resolved
(from [09ddca67acbb88e2fdd7300670839cbf647b2694]) Fix problem with duplicated records when a :uniq :through association is preloaded [#2447 state:resolved] https://github.com/rails/rails/commit/09ddca67acbb88e2fdd7300670839...
-
Sean Hussey April 18th, 2011 @ 08:37 PM
I realize this is long-closed, by is there any reason why it wasn't backported to 2.3.x? It was originally reported on the 2.3 branch, but this fix wasn't included in the 2.3.11 release (almost 2 months after this patch was applied).
I've got it handled in my apps now, but it seems like this was lost in the shuffle (reported 4/2009, recategorized 5/2010, patched 12/2010).
-
Jon Leighton April 18th, 2011 @ 08:58 PM
Sean, the 2.3 branch is not having any further releases. If you would like to backport the patch to the 3-0-stable branch then feel free and I will apply it.
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
Referenced by
- 2447 :uniq option doesn't work with has_many :through and eager loading (from [09ddca67acbb88e2fdd7300670839cbf647b2694]) Fix pro...