This project is archived and is in readonly mode.
default_scope Errors with named_scope
Reported by Peter Leonhardt | March 10th, 2009 @ 06:44 PM | in 2.x
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 } }
Comments and changes to this ticket
-
Peter Wagenet March 19th, 2009 @ 02:06 PM
- 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...
-
Peter Leonhardt March 26th, 2009 @ 12:55 AM
- Tag changed from 2.3-rc2, activerecord, default_scope, named_scope, scope to 2.3-rc2, activerecord, bug, default_scope, named_scope, scope
-
Steve St. Martin April 16th, 2010 @ 12:51 AM
- Assigned user set to Ryan Bigg
duplicates #2371, mark as duplicate
-
Ryan Bigg April 16th, 2010 @ 12:55 AM
- State changed from new to duplicate
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
Referenced by
- 2371 Default scope with :conditions => "a string" This patch also fixes the #2199 bug (with a test case to ...
- 2654 [Patch] default_scope should ignore string conditions on new/create Ticket #2199 seems related.