- Fixed a bug where withJoin() would mess with previous select() done on querybuilding

- Fixed a problem related with distinct in select whenever another select on fields was done
This commit is contained in:
Dave Mc Nicoll 2025-03-20 17:28:56 +00:00
parent bfddf84564
commit 9556dea849
2 changed files with 7 additions and 4 deletions

View File

@ -59,7 +59,7 @@ class MysqlQueryBuilder extends SqlQueryBuilder
$this->push($select);
}
$select->distinct = $distinct;
$select->distinct = $select->distinct || $distinct;
return $this;
}

View File

@ -407,7 +407,9 @@ class Repository implements RepositoryInterface
public function withJoin(string|array $fields, array $options = []) : self
{
if ( null === $this->queryBuilder->getFragment(Query\Select::class) ) {
$canSelect = null === $this->queryBuilder->getFragment(Query\Select::class);
if ( $canSelect ) {
$select = $this->entityResolver->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $select)));
}
@ -442,8 +444,9 @@ class Repository implements RepositoryInterface
$name = $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Field::class ])->name ?? $field->name;
$this->select("$escAlias.$fieldName as $alias\${$name}");
if ($canSelect) {
$this->select("$escAlias.$fieldName as $alias\${$name}");
}
}
}