On Feb 16, 2011, at 4:53 AM, Colin Law <[email protected]> wrote:

> HI
>
> I notice on Rails 3.0.4 that the following two statements generate
> different results.
>
> State.where(:abbreviation => 'TX').where(:abbreviation => 'NE')
> SQL: SELECT `states`.* FROM `states` WHERE (`states`.`abbreviation` =
> 'TX') OR (`states`.`abbreviation` = 'NE')
>
> State.where(:abbreviation => 'TX').where("abbreviation = 'NE'")
> SQL: SELECT `states`.* FROM `states` WHERE (`states`.`abbreviation` =
> 'TX') AND (`states`.`abbreviation` = 'NE')
>
> Using Rails 3.0.3 they both generated AND clauses which seems to me to
> be correct.
>
> Is this a bug or by design please?
>
> Colin

The OR functionality is new, but intentional. See
Relation::QueryMethods#collapse_wheres. Since the idea of having a
column being equal to two different values doesn't make sense,
equalities with the same left-hand side get combined with OR, which is
more likely the desired result if two scopes are merged and both
include equality conditions on the same column.

Since your example above used a string in the second where call, it
didn't result in an Arel::Nodes::Equality, so it wasn't ORed.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to