lib/mongoid/association/constrainable.rb
# Convert the supplied object to the appropriate type to set as the
# foreign key for a relation.
#
# @example Convert the object.
#   constraint.convert("12345")
#
# @param [ Object ] object The object to convert.
#
# @return [ Object ] The object cast to the correct type.
#
# @since 2.0.0.rc.7
Convert the supplied object to the appropriate type to set as the
foreign key for a relation.
Convert the supplied object to the appropriate type to set as the foreign key for a relation .
def convert_to_foreign_key(object)
        return convert_polymorphic(object) if polymorphic?
        field = relation_class.fields["_id"]
        if relation_class.using_object_ids?
          BSON::ObjectId.mongoize(object)
        elsif object.is_a?(::Array)
          object.map!{ |obj| field.mongoize(obj) }
        else
          field.mongoize(object)
        end
      end
def convert_to_foreign_key ( object ) return convert_polymorphic ( object ) if polymorphic? field = relation_class . fields [ "_id" ] if relation_class . using_object_ids? BSON :: ObjectId . mongoize ( object ) elsif object . is_a? ( :: Array ) object . map! { | obj | field . mongoize ( obj ) } else field . mongoize ( object ) end end
Convert the supplied object to the appropriate type to set as the
foreign key for a relation.
Convert the supplied object to the appropriate type to set as the foreign key for a relation .
The object cast to the correct type.
The object cast to the correct type .
 Object 
object
object The object to convert.
object The object to convert .
example
Convert the object.
Convert the object .
since
None