Module: Mongoid::Persistable::Renamable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Mongoid::Persistable
- Defined in:
- lib/mongoid/persistable/renamable.rb
Overview
Defines behaviour for $rename operations.
Instance Method Summary collapse
-
#rename(renames) ⇒ true, false
Rename fields from one value to another via $rename.
Instance Method Details
#rename(renames) ⇒ true, false
Note:
This does not work for fields in embeds many relations.
Rename fields from one value to another via $rename.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mongoid/persistable/renamable.rb', line 23 def rename(renames) prepare_atomic_operation do |ops| process_atomic_operations(renames) do |old_field, new_field| new_name = new_field.to_s attributes[new_name] = attributes.delete(old_field) ops[atomic_attribute_name(old_field)] = atomic_attribute_name(new_name) end { "$rename" => ops } end end |