lib/db/cortex.php
protected function getForeignKeysArray($val, $rel_field, $key) {
		if (is_null($val))
			return NULL;
		if (is_object($val) && $val instanceof CortexCollection)
			$val = $val->getAll($rel_field,true);
		elseif (is_string($val))
			// split-able string of collection IDs
			$val = \Base::instance()->split($val);
		elseif (!is_array($val) && !(is_object($val)
				&& ($val instanceof Cortex && !$val->dry())))
			trigger_error(sprintf(self::E_MM_REL_VALUE, $key),E_USER_ERROR);
		// hydrated mapper as collection
		if (is_object($val)) {
			$nval = array();
			while (!$val->dry()) {
				$nval[] = $val->get($rel_field,true);
				$val->next();
			}
			$val = $nval;
		}
		elseif (is_array($val)) {
			// array of single hydrated mappers, raw ID value or mixed
			$isMongo = ($this->dbsType == 'mongo');
			foreach ($val as &$item) {
				if (is_object($item) &&
					!($isMongo && (($this->db->legacy() && $item instanceof \MongoId) ||
						(!$this->db->legacy() && $item instanceof \MongoDB\BSON\ObjectId)))) {
					if (!$item instanceof Cortex || $item->dry())
						trigger_error(self::E_INVALID_RELATION_OBJECT,E_USER_ERROR);
					else $item = $item->get($rel_field,true);
				}
				if ($isMongo && $rel_field == '_id' && is_string($item))
					$item = $this->db->legacy() ? new \MongoId($item) : new \MongoDB\BSON\ObjectId($item);
				if (is_numeric($item))
					$item = (int) $item;
				unset($item);
			}
		}
		return $val;
	}
protected function getForeignKeysArray($val, $rel_field, $key) {
		if (is_null($val))
			return NULL;
		if (is_object($val) && $val instanceof CortexCollection)
			$val = $val->getAll($rel_field,true);
		elseif (is_string($val))
			// split-able string of collection IDs
			$val = \Base::instance()->split($val);
		elseif (!is_array($val) && !(is_object($val)
				&& ($val instanceof Cortex && !$val->dry())))
			trigger_error(sprintf(self::E_MM_REL_VALUE, $key),E_USER_ERROR);
		// hydrated mapper as collection
		if (is_object($val)) {
			$nval = array();
			while (!$val->dry()) {
				$nval[] = $val->get($rel_field,true);
				$val->next();
			}
			$val = $nval;
		}
		elseif (is_array($val)) {
			// array of single hydrated mappers, raw ID value or mixed
			$isMongo = ($this->dbsType == 'mongo');
			foreach ($val as &$item) {
				if (is_object($item) &&
					!($isMongo && (($this->db->legacy() && $item instanceof \MongoId) ||
						(!$this->db->legacy() && $item instanceof \MongoDB\BSON\ObjectId)))) {
					if (!$item instanceof Cortex || $item->dry())
						trigger_error(self::E_INVALID_RELATION_OBJECT,E_USER_ERROR);
					else $item = $item->get($rel_field,true);
				}
				if ($isMongo && $rel_field == '_id' && is_string($item))
					$item = $this->db->legacy() ? new \MongoId($item) : new \MongoDB\BSON\ObjectId($item);
				if (is_numeric($item))
					$item = (int) $item;
				unset($item);
			}
		}
		return $val;
	}
protected function getForeignKeysArray ( $ val , $ rel_field , $ key ) { if ( is_null ( $ val ) ) return NULL ; if ( is_object ( $ val ) && $ val instanceof CortexCollection ) $ val = $ val -> getAll ( $ rel_field , true ) ; elseif ( is_string ( $ val ) ) // split-able string of collection IDs $ val = \ Base :: instance ( ) -> split ( $ val ) ; elseif ( ! is_array ( $ val ) && ! ( is_object ( $ val ) && ( $ val instanceof Cortex && ! $ val -> dry ( ) ) ) ) trigger_error ( sprintf ( self :: E_MM_REL_VALUE , $ key ) , E_USER_ERROR ) ; // hydrated mapper as collection if ( is_object ( $ val ) ) { $ nval = array ( ) ; while ( ! $ val -> dry ( ) ) { $ nval [ ] = $ val -> get ( $ rel_field , true ) ; $ val -> next ( ) ; } $ val = $ nval ; } elseif ( is_array ( $ val ) ) { // array of single hydrated mappers, raw ID value or mixed $ isMongo = ( $ this -> dbsType == 'mongo' ) ; foreach ( $ val as & $ item ) { if ( is_object ( $ item ) && ! ( $ isMongo && ( ( $ this -> db -> legacy ( ) && $ item instanceof \ MongoId ) || ( ! $ this -> db -> legacy ( ) && $ item instanceof \ MongoDB \ BSON \ ObjectId ) ) ) ) { if ( ! $ item instanceof Cortex || $ item -> dry ( ) ) trigger_error ( self :: E_INVALID_RELATION_OBJECT , E_USER_ERROR ) ; else $ item = $ item -> get ( $ rel_field , true ) ; } if ( $ isMongo && $ rel_field == '_id' && is_string ( $ item ) ) $ item = $ this -> db -> legacy ( ) ? new \ MongoId ( $ item ) : new \ MongoDB \ BSON \ ObjectId ( $ item ) ; if ( is_numeric ( $ item ) ) $ item = ( int ) $ item ; unset ( $ item ) ; } } return $ val ; }
find the ID values of given relation collection
@param $val string|array|object|bool
@param $rel_field string
@param $key string
@return array|Cortex|null|object
find the ID values of given relation collection