Forráskód Böngészése

add support for selecting specific columns in QueryBuilder

phpdevcommunity 1 hónapja
szülő
commit
552c5bcbf4
2 módosított fájl, 5 hozzáadás és 8 törlés
  1. 1 0
      src/Query/QueryBuilder.php
  2. 4 8
      src/Repository/Repository.php

+ 1 - 0
src/Query/QueryBuilder.php

@@ -311,6 +311,7 @@ final class QueryBuilder
             $properties = ColumnMapper::getColumns($entityName);
         }
         $columns = $this->convertPropertiesToColumns($entityName, $properties);
+
         $primaryKey = ColumnMapper::getPrimaryKeyColumnName($entityName);
         $primaryKeyQuoted = $this->schema->quote($primaryKey);
         if (!in_array($primaryKeyQuoted, $columns)) {

+ 4 - 8
src/Repository/Repository.php

@@ -6,11 +6,9 @@ use InvalidArgumentException;
 use PhpDevCommunity\PaperORM\Entity\EntityInterface;
 use PhpDevCommunity\PaperORM\EntityManagerInterface;
 use PhpDevCommunity\PaperORM\Expression\Expr;
-use PhpDevCommunity\PaperORM\Hydrator\EntityHydrator;
 use PhpDevCommunity\PaperORM\Mapper\ColumnMapper;
 use PhpDevCommunity\PaperORM\Mapper\EntityMapper;
 use PhpDevCommunity\PaperORM\Persistence\EntityPersistence;
-use PhpDevCommunity\PaperORM\Platform\PlatformInterface;
 use PhpDevCommunity\PaperORM\Query\Fetcher;
 use PhpDevCommunity\PaperORM\Query\QueryBuilder;
 use Psr\EventDispatcher\EventDispatcherInterface;
@@ -57,12 +55,10 @@ abstract class Repository
             } elseif (is_null($value)) {
                 $expressions[] = Expr::isNull($key);
                 continue;
-            }
-            elseif (is_string($value) && strtoupper($value) === "!NULL") {
+            } elseif (is_string($value) && strtoupper($value) === "!NULL") {
                 $expressions[] = Expr::isNotNull($key);
                 continue;
-            }
-            elseif (!is_scalar($value)) {
+            } elseif (!is_scalar($value)) {
                 throw new InvalidArgumentException(
                     sprintf('Argument "%s" must be scalar, array, null or EntityInterface, %s given', $key, gettype($value))
                 );
@@ -101,9 +97,9 @@ abstract class Repository
         return $rows;
     }
 
-    public function qb(): QueryBuilder
+    public function qb(...$propertiesToSelect): QueryBuilder
     {
         $queryBuilder = new QueryBuilder($this->em);
-        return $queryBuilder->select($this->getEntityName());
+        return $queryBuilder->select($this->getEntityName(), $propertiesToSelect);
     }
 }