module Mongoid::Persistable::Renamable

def rename(renames)

Other tags:
    Since: - 4.0.0

Returns:
  • (Document) - The document.

Parameters:
  • renames (Hash) -- The rename pairs of old name/new name.

Other tags:
    Note: - This does not work for fields in embeds many associations.

Other tags:
    Example: Rename the fields. -
def rename(renames)
  prepare_atomic_operation do |ops|
    process_atomic_operations(renames) do |old_field, new_field|
      new_name = new_field.to_s
      if executing_atomically?
        process_attribute new_name, attributes[old_field]
        process_attribute old_field, nil
      else
        attributes[new_name] = attributes.delete(old_field)
      end
      ops[atomic_attribute_name(old_field)] = atomic_attribute_name(new_name)
    end
    { "$rename" => ops }
  end
end