lib/mongoid/association/constrainable.rb
# Convert the supplied object to the appropriate type to set as the
# foreign key for an association.
#
# @example Convert the object.
#   constraint.convert("12345")
#
# @param [ Object ] object The object to convert.
#
# @return [ Object ] The object cast to the correct type.
Convert the supplied object to the appropriate type to set as the
foreign key for an association.
Convert the supplied object to the appropriate type to set as the foreign key for an association .
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 an association.
Convert the supplied object to the appropriate type to set as the foreign key for an association .
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 .