Spot\Entity::relation PHP Method

relation() public method

Get/Set relation
public relation ( string $relationName, null $relationObj = null ) : boolean | mixed
$relationName string
$relationObj null
return boolean | mixed
    public function relation($relationName, $relationObj = null)
    {
        // Local static property instead of class variable prevents the
        // relation object, mapper, and connection info
        // from being printed with a var_dump() of the entity
        static $relations = [];
        $objectId = $this->_objectId;
        // Get relation
        if ($relationObj === null) {
            if (isset($relations[$objectId][$relationName])) {
                return $relations[$objectId][$relationName];
            }
            return false;
        } elseif ($relationObj === false) {
            // Unset relation
            if (isset($relations[$objectId][$relationName])) {
                unset($relations[$objectId][$relationName]);
            }
            return false;
        } else {
            // Set relation
            $relations[$objectId][$relationName] = $relationObj;
            // Add to relation field array
            $entityName = get_class($this);
            if (!isset(self::$relationFields[$entityName]) || !in_array($relationName, self::$relationFields[$entityName])) {
                if (!isset(self::$relationFields[$entityName])) {
                    self::$relationFields[$entityName] = [];
                }
                self::$relationFields[$entityName][] = $relationName;
            }
        }
        return $relations[$objectId][$relationName];
    }