This project is archived and is in readonly mode.

#2654 ✓duplicate
Andrew Vit

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

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

Attachments

Pages