-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: 5.2.1
-
Component/s: Query
-
None
-
any? on has_many associations no longer retrieves the entire association from the database. This makes any? more efficient in most cases, but repeated calls to any? when the association is not loaded will query the database on every call.
-
Minor Change
I have a simple class:
class Article include Mongoid::Document end
Here are some simple queries with the mongo query made:
Article.criteria.any? => {"find"=>"articles", "filter"=>{}} Article.criteria.exists? # or empty? or blank? or present? => {"find"=>"articles", "filter"=>{}, "projection"=>{"_id"=>1}, "limit"=>1}
I couldn't find the reason why any? is not optimized like the other methods. Is there an explanation? And can we improve this?
- is related to
-
MONGOID-4830 Remove #one method from has_many associations
- Closed
-
MONGOID-4959 Document any? in tutorial
- Closed
- related to
-
MONGOID-4890 Destroying model instances with dependent associations in transactions raises OperationFailure due to use of (deprecated) count
- Closed
- links to