Class: Mongoid::Fields::Internal::ForeignKeys::Array
- Includes:
- Serializable
- Defined in:
- lib/mongoid/fields/internal/foreign_keys/array.rb
Overview
Defines the behaviour for array foreign key fields.
Instance Attribute Summary
Attributes included from Serializable
#default_val, #label, #localize, #name, #options
Instance Method Summary collapse
-
#add_atomic_changes(document, key, mods, new, old) ⇒ Object
Adds the atomic changes for this type of resizable field.
-
#object_id_field? ⇒ true, false
Is the field a BSON::ObjectId?.
-
#resizable? ⇒ true
Array fields are resizable.
-
#serialize(object) ⇒ Array
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
Methods included from Serializable
#constraint, #deserialize, #eval_default, #foreign_key?, #localized?, #metadata, #selection, #type, #versioned?
Instance Method Details
#add_atomic_changes(document, key, mods, new, old) ⇒ Object
Adds the atomic changes for this type of resizable field.
23 24 25 26 27 28 29 30 31 |
# File 'lib/mongoid/fields/internal/foreign_keys/array.rb', line 23 def add_atomic_changes(document, key, mods, new, old) if new.any? && old.any? mods[key] = document.attributes[key] elsif new.any? document.atomic_array_add_to_sets[key] = new elsif old.any? document.atomic_array_pulls[key] = old end end |
#object_id_field? ⇒ true, false
Is the field a BSON::ObjectId?
41 42 43 44 |
# File 'lib/mongoid/fields/internal/foreign_keys/array.rb', line 41 def object_id_field? @object_id_field ||= .polymorphic? ? true : .klass.using_object_ids? end |
#resizable? ⇒ true
Array fields are resizable.
54 |
# File 'lib/mongoid/fields/internal/foreign_keys/array.rb', line 54 def resizable?; true; end |
#serialize(object) ⇒ Array
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
67 68 69 |
# File 'lib/mongoid/fields/internal/foreign_keys/array.rb', line 67 def serialize(object) object ? constraint.convert(object) : [] end |