symfony fetch unique

    public function getWarehouseDataByCode(string $code, array $fields)
    {
        $queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder()
            ->select(...$fields)
            ->from($this->getClassMetadata()->getTableName(), 'w')
            ->andWhere('w.code = :code')
            ->andWhere('w.deleted_at IS NULL')
            ->setParameter('code', $code, PDO::PARAM_STR);

        return $queryBuilder->execute()->fetchAll(PDO::FETCH_UNIQUE);
    }
$test = getWarehouseDataByCode('xxxx', ['id']));
//zwróci
array:1 [▼
  5539 => array:1 [▼
    "code" => "virtual_sum_ec_pl"
  ]
]
Komentarze wyłączone