Module: Mongoid::Fields::ClassMethods

Defined in:
lib/custom_fields/extensions/mongoid/fields.rb

Instance Method Summary collapse

Instance Method Details

#replace_field(name, type, localize = false) ⇒ Serializable

Replace a field with a new type.

Examples:

Replace the field.

Model.replace_field("_id", String)

Parameters:

  • name (String)

    The name of the field.

  • type (Class)

    The new type of field.

  • localize (Boolean) (defaults to: false)

    The option to localize or not the field.

Returns:

  • (Serializable)

    The new field.

Since:

  • 2.1.0



21
22
23
24
25
# File 'lib/custom_fields/extensions/mongoid/fields.rb', line 21

def replace_field(name, type, localize = false)
  # puts "fields[#{name}] = #{fields[name.to_s].inspect} / #{fields.keys.inspect}" # DEBUG
  remove_defaults(name)
  add_field(name, fields[name.to_s].options.merge(type: type, localize: localize))
end