diff --git a/src/Collection/ReadBuilder/ReadBuilder.php b/src/Collection/ReadBuilder/ReadBuilder.php index 3d100b3..2526890 100644 --- a/src/Collection/ReadBuilder/ReadBuilder.php +++ b/src/Collection/ReadBuilder/ReadBuilder.php @@ -184,8 +184,6 @@ 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(), @@ -193,11 +191,17 @@ public function createQueryBuilder(EntityRepository $repo, string $alias): Query $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;