Method: Mongoid::Criteria#only

Defined in:
lib/mongoid/criteria.rb

#only(*args) ⇒ Criteria

Overriden to include _type in the fields.

Examples:

Limit the fields returned from the database.

Band.only(:name)

Parameters:

  • args (Array<Symbol>)

    The names of the fields.

Returns:

Since:

  • 1.0.0



334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/mongoid/criteria.rb', line 334

def only(*args)
  return clone if args.flatten.empty?
  args = args.flatten
  if (args & Fields::IDS).empty?
    args.unshift(:_id)
  end
  if klass.hereditary?
    super(*args.push(:_type))
  else
    super(*args)
  end
end