Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

:uniq option doesn't work with has_many :through and eager loading

#2447


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

Reported by DerGuteMoritz · April 7th, 2009 @ 08:41 PM

State: resolved
Milestone: 3.x
Assigned to: Aaron Patterson Aaron Patterson
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  2. Jon Leighton
    Jon Leighton
    • 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.

    December 16th, 2010 @ 12:51 AM

  3. Repository
  4. Sean Hussey
    Sean Hussey

    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).

    April 18th, 2011 @ 08:37 PM

  5. Jon Leighton
    Jon Leighton

    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.

    April 18th, 2011 @ 08:58 PM