From 2a3d273f99a5931f56f9654aab84c12ca3bc4852 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 4 Nov 2020 20:41:47 +0100 Subject: [PATCH] added get by parent function --- DataStorage/Database/DataMapperAbstract.php | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 68c029676..3a4aa10be 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -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. *