Method: Mongoid::Factory#execute_from_db

Defined in:
lib/mongoid/factory.rb

#execute_from_db(klass, attributes = nil, criteria = nil, selected_fields = nil, execute_callbacks: Threaded.execute_callbacks?) ⇒ Document

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute from_db.

Parameters:

  • klass (Class)

    The class to instantiate from if _type is not present.

  • attributes (Hash) (defaults to: nil)

    The document attributes.

  • criteria (Criteria) (defaults to: nil)

    Optional criteria object.

  • selected_fields (Hash) (defaults to: nil)

    Fields which were retrieved via #only. If selected_fields are specified, fields not listed in it will not be accessible in the returned document.

  • execute_callbacks (true | false) (defaults to: Threaded.execute_callbacks?)

    Whether this method should invoke the callbacks. If true, the callbacks will be invoked normally. If false, the callbacks will be stored in the pending_callbacks list and caller is responsible for invoking run_pending_callbacks at a later time. Use this option to defer callback execution until the entire object graph containing embedded associations is constructed.

Returns:

  • (Document)

    The instantiated document.



234
235
236
237
238
239
# File 'lib/mongoid/factory.rb', line 234

def execute_from_db(klass, attributes = nil, criteria = nil,
                    selected_fields = nil,
                    execute_callbacks: Threaded.execute_callbacks?)
  Instantiator.new(klass, attributes, criteria, selected_fields)
              .instance(execute_callbacks: execute_callbacks)
end