Class: Mongoid::Fields::Internal::ObjectId
- Includes:
- Serializable
- Defined in:
- lib/mongoid/fields/internal/object_id.rb
Overview
Defines the behaviour for BSON::ObjectId fields.
Instance Attribute Summary
Attributes included from Serializable
#default_val, #label, #localize, #name, #options
Instance Method Summary collapse
-
#selection(object) ⇒ Object
Special case to serialize the object.
-
#serialize(object) ⇒ BSON::ObjectId
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, #object_id_field?, #resizable?, #type, #versioned?
Instance Method Details
#selection(object) ⇒ Object
Special case to serialize the object.
20 21 22 23 |
# File 'lib/mongoid/fields/internal/object_id.rb', line 20 def selection(object) return object if object.is_a?(::Hash) serialize(object) end |
#serialize(object) ⇒ BSON::ObjectId
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
36 37 38 39 40 41 42 |
# File 'lib/mongoid/fields/internal/object_id.rb', line 36 def serialize(object) if object.is_a?(::String) BSON::ObjectId.from_string(object) unless object.blank? else object end end |