Class: Mongoid::Relations::Constraint
- Inherits:
-
Object
- Object
- 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)
-
- (Object) metadata
readonly
Returns the value of attribute metadata.
Instance Method Summary (collapse)
-
- (Object) convert(object)
Convert the supplied object to the appropriate type to set as the foreign key for a relation.
-
- (Constraint) initialize(metadata)
constructor
Create the new constraint with the metadata.
Constructor Details
- (Constraint) initialize(metadata)
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
- (Object) metadata (readonly)
Returns the value of attribute metadata
11 12 13 |
# File 'lib/mongoid/relations/constraint.rb', line 11 def @metadata end |
Instance Method Details
- (Object) convert(object)
Convert the supplied object to the appropriate type to set as the foreign key for a relation.
36 37 38 39 40 |
# File 'lib/mongoid/relations/constraint.rb', line 36 def convert(object) return object if .polymorphic? klass = .klass klass.using_object_ids? ? BSON::ObjectId.mongoize(object) : object end |