From fb644b0b0a178210f9948e6b70f0806cf0e7685a Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 3 Jun 2025 20:27:15 +0000 Subject: [PATCH] - Added withJoin from attributes in RelationBuilder (can't understand why it wasn't already..) --- src/Attribute/Property/WithJoin.php | 2 +- src/Repository/RelationBuilder.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Attribute/Property/WithJoin.php b/src/Attribute/Property/WithJoin.php index 7f5be96..b3f05b4 100644 --- a/src/Attribute/Property/WithJoin.php +++ b/src/Attribute/Property/WithJoin.php @@ -5,6 +5,6 @@ namespace Ulmus\Attribute\Property; #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)] class WithJoin { public function __construct( - array $joins = [] + public array $joins = [] ) {} } diff --git a/src/Repository/RelationBuilder.php b/src/Repository/RelationBuilder.php index 94b25b4..00b8e15 100644 --- a/src/Repository/RelationBuilder.php +++ b/src/Repository/RelationBuilder.php @@ -177,6 +177,13 @@ class RelationBuilder } } + protected function applyWithJoin() : void + { + foreach($this->joins as $item) { + $this->repository->withJoin($item->joins); + } + } + protected function instanciateEmptyEntity(string $name, Relation $relation) : object { $class = $relation->entity ?? $this->resolver->reflectedClass->getProperties()[$name]->getTypes()[0]->type; @@ -270,6 +277,8 @@ class RelationBuilder $this->applyOrderBy(); + $this->applyWithJoin(); + $field = $relation->key; if ($relation->foreignKey) { @@ -313,6 +322,8 @@ class RelationBuilder $this->applyOrderBy(); + $this->applyWithJoin(); + if ($selectBridgeField && $relation->bridgeField) { $this->repository->selectEntity($relation->bridge, $bridgeAlias, $bridgeAlias); }