This project is archived and is in readonly mode.
NamedScope#any?
-
Tarmo Tänav
Actually neither should be doing count() as exists?({}) is much faster (it's faster to fetch one record compared to counting them all).
-
Tarmo Tänav
Ofcourse exists?() should not be used in case the records are already loaded.
-
Repository
- State changed from new to resolved
(from [93e10f9911fb2a096681ee0a0bc82487a9a06c44]) Ensure NamedScope#any? uses COUNT query wherever possible. [#680 state:resolved]
Signed-off-by: Pratik Naik
-
Paweł Kondzior
Method
any?is not the same as!empty?[nil].any? will return false [nil].empty? will return false
But maybe here there is no case when AR can return [nil,nil,nil] array. But i think rails shouldn't break MRI here.
-
Tarmo Tänav
If there was a case where an association would return [nil] it would by itself be an error in AR so there can't be a a case where any? on associations wcould behave differently than on arrays.