This project is archived and is in readonly mode.
default_scope should ignore string conditions on new/create
Reported by Andrew Vit | May 15th, 2009 @ 08:48 PM | in 2.x
Using a condition string like {:conditions => "state != 'active'"} in a default_scope is not possible because it expects a hash to assign the values into the model attributes when initializing.
The following error is raised when it tries to call the string conditions as an attribute assignment:
1)
undefined method `state != 'active'=' for #<Model:0x33bac74>
This patch checks the default_scope options and only assigns the values to the model if the conditions option is a Hash. If it's a string, it's ignored.
This means that if you use a string for default_scope conditions and you expect default values, you should set these in an initialize method or else before_create.
(This patch is against 2.3-stable)
Comments and changes to this ticket
-
Andrew Vit May 15th, 2009 @ 09:17 PM
Don't know what happened with my patch file there... This is the correct one.
-
Andrew Vit May 15th, 2009 @ 09:41 PM
- no changes were found...
-
Andrew Vit May 18th, 2009 @ 12:44 AM
- Assigned user set to Manfred Stienstra
Also #2371.
Manfred, I hear you're the one working on a scopes rewrite: so I'm assigning this to you.
Any chance of a quick-fix for this in 2.3 before the rewrite?
-
Andrew Vit May 19th, 2009 @ 06:39 PM
Looks like this is now fixed by #2181
97b75c9f1668992bd246fe46235c5764a4fa6e58Please close.
-
Pratik May 19th, 2009 @ 07:04 PM
- Title changed from [Patch] default_scope should ignore string conditions on new/create to default_scope should ignore string conditions on new/create
- 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>