MongoDBRef::create PHP Method

create() public static method

If no database is given, the current database is used.
public static create ( string $collection, mixed $id, string $database = null ) : array
$collection string Collection name (without the database name)
$id mixed The _id field of the object to which to link
$database string Database name
return array Returns the reference
    public static function create($collection, $id, $database = null)
    {
        $ref = [static::$refKey => $collection, static::$idKey => $id];
        if ($database !== null) {
            $ref['$db'] = $database;
        }
        return $ref;
    }

Usage Example

Example #1
0
 /**
  * Creates a new database reference
  *
  * @param string|\Phalcon\Mvc\Collection $collection
  * @param mixed|\MongoId|\Phalcon\Mvc\Collection $id
  * @param string $database
  * @return array
  */
 public static function create($collection, $id = null, $database = null)
 {
     if ($collection instanceof \Phalcon\Mvc\Collection) {
         $id = $collection->getId();
         $collection = $collection->getSource();
     }
     if ($id instanceof \Phalcon\Mvc\Collection) {
         $id = $id->getId();
     }
     if (is_array($collection) && self::isRef($collection)) {
         if (isset($collection['$id'])) {
             $id = $collection['$id'];
         }
         if (isset($collection['$ref'])) {
             $collection = $collection['$ref'];
         }
     }
     if (!$id instanceof \MongoId && $id !== null) {
         $id = new \MongoId($id);
     }
     if ($collection instanceof \MongoId) {
         return $collection;
     }
     if ($id === null) {
         return null;
     }
     return parent::create($collection, $id, $database);
 }
All Usage Examples Of MongoDBRef::create