Bluz\Db\Relations::getRelations PHP Method

getRelations() public static method

Get relations
public static getRelations ( string $modelOne, string $modelTwo ) : array | false
$modelOne string
$modelTwo string
return array | false
    public static function getRelations($modelOne, $modelTwo)
    {
        $name = [$modelOne, $modelTwo];
        sort($name);
        $name = join(':', $name);
        return self::$relations[$name] ?? false;
    }

Usage Example

Beispiel #1
0
 /**
  * findRelation
  *
  * @param  Row $row
  * @param  string $relation
  * @return array
  * @throws Exception\RelationNotFoundException
  */
 public static function findRelation($row, $relation)
 {
     $model = $row->getTable()->getModel();
     /** @var \Bluz\Db\Table $relationTable */
     $relationTable = Relations::getModelClass($relation);
     $relationTable::getInstance();
     if (!($relations = Relations::getRelations($model, $relation))) {
         throw new RelationNotFoundException("Relations between model `{$model}` and `{$relation}` is not defined");
     }
     // check many-to-many relations
     if (sizeof($relations) == 1) {
         $relations = Relations::getRelations($model, current($relations));
     }
     $field = $relations[$model];
     $key = $row->{$field};
     return Relations::findRelations($model, $relation, [$key]);
 }