Module: Mongoid::Association::Referenced::HasAndBelongsToMany::Buildable
- Defined in:
- lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb
Overview
The Builder behavior for has_and_belongs_to_many associations.
Instance Method Summary collapse
-
#build(_base, object, _type = nil, selected_fields = nil) ⇒ Array<Document>
This builder either takes a hash and queries for the object or an array of documents, where it will just return them.
Instance Method Details
#build(_base, object, _type = nil, selected_fields = nil) ⇒ Array<Document>
This builder either takes a hash and queries for the object or an array of documents, where it will just return them.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb', line 21 def build(_base, object, _type = nil, selected_fields = nil) if query?(object) # Handle array of hashes from $lookup aggregation if object.is_a?(Array) && object.all? { |o| o.is_a?(Hash) } return object.map do |attrs| Factory.execute_from_db(klass, attrs, nil, selected_fields, execute_callbacks: false) end end query_criteria(object) else object.try(:dup) end end |