From 9b5fd9d3221781a26f5fd65124a4ca08c31c5435 Mon Sep 17 00:00:00 2001 From: Tony NGUEREZA Date: Wed, 26 Jun 2024 02:49:44 +0100 Subject: [PATCH] Update permission entity to add parent field relationship --- src/Auth/Entity/Permission.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Auth/Entity/Permission.php b/src/Auth/Entity/Permission.php index 7315a73..7acff10 100644 --- a/src/Auth/Entity/Permission.php +++ b/src/Auth/Entity/Permission.php @@ -49,6 +49,8 @@ use Platine\Orm\Entity; use Platine\Orm\Mapper\EntityMapperInterface; +use Platine\Orm\Query\Query; +use Platine\Orm\Relation\ForeignKey; /** * @class Permission @@ -71,5 +73,13 @@ public static function mapEntity(EntityMapperInterface $mapper): void ]); $mapper->relation('roles')->shareMany(Role::class); + $mapper->relation('parent')->belongsTo(Permission::class, new ForeignKey([ + 'id' => 'parent_id' + ])); + + + $mapper->filter('parent', function (Query $q, $value) { + $q->where('parent_id')->is($value); + }); } }