added get by parent function

This commit is contained in:
Dennis Eichhorn 2020-11-04 20:41:47 +01:00
parent 6a6351a275
commit 2a3d273f99

View File

@ -182,6 +182,14 @@ class DataMapperAbstract implements DataMapperInterface
*/
protected static string $table = '';
/**
* Parent column.
*
* @var string
* @since 1.0.0
*/
protected static string $parent = '';
/**
* Model to use by the mapper.
*
@ -2826,6 +2834,24 @@ class DataMapperAbstract implements DataMapperInterface
return self::getAllByQuery($query, $relations, $depth);
}
/**
* Parent parent.
*
* @param int $depth Relation depth
* @param mixed $value Parent value id
*
* @return array
*
* @since 1.0.0
*/
public static function getByParent($value, int $depth = 3) : array
{
$query = self::getQuery();
$query->where(static::$table . '_' . $depth . '.' . static::$parent, '=', $value);
return self::getAllByQuery($query, RelationType::ALL, $depth);
}
/**
* Get all by custom query.
*