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); }