123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Persistable::Unsettable

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ActiveSupport::Concern
Defined in: lib/mongoid/persistable/unsettable.rb

Overview

Defines behavior for $unset operations.

Instance Method Summary

Instance Method Details

#unset(*fields) ⇒ Document

Perform an $unset operation on the provided fields and in the values in the document in memory.

Examples:

Unset the values.

document.unset(:first_name, :last_name, :middle)

Parameters:

Returns:

[ GitHub ]

  
# File 'lib/mongoid/persistable/unsettable.rb', line 21

def unset(*fields)
  prepare_atomic_operation do |ops|
    fields.flatten.each do |field|
      normalized = database_field_name(field)
      if executing_atomically?
        process_attribute normalized, nil
      else
        attributes.delete(normalized)
      end
      ops[atomic_attribute_name(normalized)] = true
    end
    { "$unset" => ops }
  end
end