On Wed, Feb 16, 2011 at 06:21:54AM -0500, Ernie Miller wrote: > 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.
The intentional change fixes this bug: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4598-default_scope-treats-hashes-and-relations-inconsistently-when-overwriting If there is a different way to fix that ticket, I'm happy to apply patches. -- Aaron Patterson http://tenderlovemaking.com/
pgpUhsAqA7nR5.pgp
Description: PGP signature
