Skip to content

Commit

Permalink
Fixed non-fetching DB columns
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaplet committed Sep 28, 2024
1 parent 607fece commit e1d6e54
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Collection/ReadBuilder/ReadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,24 @@ public function createQueryBuilder(EntityRepository $repo, string $alias): Query
->createQueryBuilder($alias)
->select($alias);

$columnNames = array_map(fn($col) => $col->getKey(), $this->columns);

$joins = array_merge(
$this->dbSchema->getOneToOneColumns(),
$this->dbSchema->getOneToManyColumns(),
$this->dbSchema->getManyToOneColumns(),
$this->dbSchema->getManyToManyColumns()
);

$columnNames = array_map(fn($col) => "{$alias}.{$col->getKey()}", $this->columns);
$joins = array_filter($joins, fn($col) => array_key_exists($col['name'], $columnNames));

// Prevent columns
if (count($joins) === 0) {
$qb->addSelect($columnNames);
}

foreach ($joins as $column) {
if (in_array($column['name'], $columnNames)) {
$qb->addSelect($column['name']);
$qb->leftJoin("{$alias}.{$column['name']}", $column['name']);
}
$qb->addSelect($column['name']);
$qb->leftJoin("{$alias}.{$column['name']}", $column['name']);
}

return $qb;
Expand Down

0 comments on commit e1d6e54

Please sign in to comment.