rails: scopes combine conditions on same attribute incorrectly
This issue exists since 3.0 (a backport would be nice if it gets fixed)
class Car < ActiveRecord::Base
scope :good, where(:id => 1)
scope :bad, where(:id => 2)
end
# using scopes
Car.good.bad
SELECT "cars".* FROM "cars" WHERE "cars"."id" = 2
# using wheres
Car.where(:id => 1).where(:id => 2)
SELECT "cars".* FROM "cars" WHERE "cars"."id" = 1 AND "cars"."id" = 2
Does the same for different attributes, especially annoying when you do logic like id => [1,2,3] + id => [2,3,4]
and expect only 2 to get returned
About this issue
- Original URL
- State: closed
- Created 12 years ago
- Comments: 46 (36 by maintainers)
Commits related to this issue
- Fix conflict between product available and search scopes Search::Base#retrieve_products would add another scope regarding spree_prices currency to the query. While in Rails < 4 the last scope would o... — committed to kennyadsl/spree by huoxito 11 years ago
- Merge pull request #9553 from neerajdotname/7365-mergin-scopes-and-where 7365 merging scopes for where clauses — committed to rails/rails by jonleighton 11 years ago
Nice to see this merged. Good work!