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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

default_scope Errors with named_scope

#2199

When using default_scope in conjunction with named_scope, a default_scope that has been defined with :condition as a String, rather than a hash will throw a "TypeError: can't convert String into Hash" from


activerecord/lib/active_record/base.rb:2132: in 'merge'
activerecord/lib/active_record/base.rb:2132: in 'with_scope'
activerecord/lib/active_record/base.rb:2110: in 'each'
activerecord/lib/active_record/base.rb:2110: in 'inject'
activerecord/lib/active_record/base.rb:2110: in 'with_scope'

The default scope works find on its own, but calling a named_scope will throw the error when, presumably, trying to merge the scopes.


default_scope {:conditions => ["expires_at > ?", Time.now] }
named_scope :globals { :conditions => {:global => true } }

Reported by Peter Leonhardt · March 10th, 2009 @ 06:44 PM

State: duplicate
Milestone: 2.x
Assigned to: Ryan Bigg Ryan Bigg
Importance: none

Activity

  1. Peter Wagenet
    Peter Wagenet
    • Tag changed from 2.3-rc2, activerecord, default_scope, scope to 2.3-rc2, activerecord, default_scope, named_scope, scope

    This is due to some odd behavior in how :create scopes are merged. Apparently it's not expected that you will provide a string to them (which default_scope may), only a hash. This is partially fixed in my patch here: http://rails.lighthouseapp.com/p...

    March 19th, 2009 @ 02:06 PM

  2. Peter Leonhardt
    Peter Leonhardt
    • Tag changed from 2.3-rc2, activerecord, default_scope, named_scope, scope to 2.3-rc2, activerecord, bug, default_scope, named_scope, scope

    March 26th, 2009 @ 12:55 AM

  3. Bruno Michel
    Bruno Michel

    My patch in #2371 also fixes this bug.

    March 30th, 2009 @ 10:55 PM

  4. Steve St. Martin
    Steve St. Martin
    • Assigned user set to Ryan Bigg

    duplicates #2371, mark as duplicate

    April 16th, 2010 @ 12:51 AM

  5. Ryan Bigg
    Ryan Bigg
    • State changed from new to duplicate

    April 16th, 2010 @ 12:55 AM