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.

scope and :select causing duplicate WHERE clause

#3369
class Address < ActiveRecord:Base

  def Address.emails
    scoped(:select => "addresses.email").map(&:email)
  end
end


# This has a duplicated WHERE clause:

>> Address.scoped(:conditions => "1 = 1").emails
Address Load (0.0ms)  SELECT addresses.email FROM `addresses` WHERE ((1 = 1) AND (1 = 1))

# However spelling out the function by hand works:

>> Address.scoped(:conditions => "1 = 1").scoped(:select => "addresses.email").map(&:email)
Address Load (1.0ms)  SELECT addresses.email FROM `addresses` WHERE (1 = 1)

Reported by Greg Hazel · October 12th, 2009 @ 11:57 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Greg Hazel
    Greg Hazel
    • Title changed from named scope and :select causing duplicate WHERE clause to scope and :select causing duplicate WHERE clause

    October 12th, 2009 @ 11:58 PM

  2. Elliot Winkler
    Elliot Winkler

    #2923 named_scope through a has_many (or has_many through) generates redundant cond... which I reported a while back also does a similar thing. I wonder if it's related.

    October 13th, 2009 @ 04:18 AM

  3. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 6th, 2010 @ 06:40 AM

  4. bingbing