/**
* 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]);
}