Class: Mongoid::Relations::Constraint
- Defined in:
- lib/mongoid/relations/constraint.rb
Overview
Note:
Durran: The name of this class is this way to match the metadata getter, and foreign_key was already taken there.
Used for converting foreign key values to the correct type based on the types of ids that the document stores.
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#convert(object) ⇒ Object
Convert the supplied object to the appropriate type to set as the foreign key for a relation.
-
#initialize(metadata) ⇒ Constraint
constructor
Create the new constraint with the metadata.
Constructor Details
#initialize(metadata) ⇒ Constraint
Create the new constraint with the metadata.
21 22 23 |
# File 'lib/mongoid/relations/constraint.rb', line 21 def initialize() @metadata = end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/mongoid/relations/constraint.rb', line 11 def @metadata end |
Instance Method Details
#convert(object) ⇒ Object
Convert the supplied object to the appropriate type to set as the foreign key for a relation.
36 37 38 39 |
# File 'lib/mongoid/relations/constraint.rb', line 36 def convert(object) return object if .polymorphic? BSON::ObjectId.convert(.klass, object) end |