This project is archived and is in readonly mode.
Chained where conditions referencing same attribute joined by OR
-
Aaron Patterson
- State changed from new to invalid
- Importance changed from to Low
This is expected behavior that fixes #4598 default_scope treats hashes and relations inconsistently when overwriting. The
ORwill only be generated when the keys are the same. AnANDwith identical columns doesn't make sense. -
Jeremy McNevin
I'm not sure I'm in agreement with this.
I would expect the where method to operate in consistent manner, and not swap AND or OR around in any case, even if the SQL being generated "doesn't make sense." I could see using chained where statements referencing the same attribute to limit the set of records I ultimately want to search.
UNICAMERAL_STATES = ['NE']
class State < ActiveRecord::Base
scope :unicameral, where(:abbreviation => UNICAMERAL_STATES) end
State.unicameral.where(:abbreviation => 'MN') # None found.Granted, someone might be able to come up with a better example than that. I guess the issue is, should chaining where statements together by default actually be able to increase the number of results that are being returned? I think using OR in this case is an unsafe assumption.