- Added withJoin from attributes in RelationBuilder (can't understand why it wasn't already..)

This commit is contained in:
Dave Mc Nicoll 2025-06-03 20:27:15 +00:00
parent c719e4a6d1
commit fb644b0b0a
2 changed files with 12 additions and 1 deletions

View File

@ -5,6 +5,6 @@ namespace Ulmus\Attribute\Property;
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)] #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
class WithJoin { class WithJoin {
public function __construct( public function __construct(
array $joins = [] public array $joins = []
) {} ) {}
} }

View File

@ -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 protected function instanciateEmptyEntity(string $name, Relation $relation) : object
{ {
$class = $relation->entity ?? $this->resolver->reflectedClass->getProperties()[$name]->getTypes()[0]->type; $class = $relation->entity ?? $this->resolver->reflectedClass->getProperties()[$name]->getTypes()[0]->type;
@ -270,6 +277,8 @@ class RelationBuilder
$this->applyOrderBy(); $this->applyOrderBy();
$this->applyWithJoin();
$field = $relation->key; $field = $relation->key;
if ($relation->foreignKey) { if ($relation->foreignKey) {
@ -313,6 +322,8 @@ class RelationBuilder
$this->applyOrderBy(); $this->applyOrderBy();
$this->applyWithJoin();
if ($selectBridgeField && $relation->bridgeField) { if ($selectBridgeField && $relation->bridgeField) {
$this->repository->selectEntity($relation->bridge, $bridgeAlias, $bridgeAlias); $this->repository->selectEntity($relation->bridge, $bridgeAlias, $bridgeAlias);
} }