Details
-
Improvement
-
Status: Closed
-
Minor - P4
-
Resolution: Fixed
-
5.2.1
-
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
Description
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?
Attachments
Issue Links
- 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