Closed gnito-org closed 7 months ago
You did not specify the type of the parameter in your setParameter()
call.
I do not want to hardcode SQLite in my app. It must work seamlessly with a PostgreSQL, MySQL or SQLite database.
Besides, how do I specify the type of parameter for below in a way that transforms the ids to binary?:
$company = $companyRepository->createQueryBuilder('c')
->andWhere('c.id IN (:ids)')
->setParameter('ids', $companyIds)
->getQuery()
->execute();
Furthermore, this query:
$companyRepository->createQueryBuilder('c')->andWhere('c.user = :user')->setParameter('user', $user, Types::BINARY)->getQuery()
crashes with:
Object of class App\Users\Entity\User could not be converted to string
public function __toString(): string
{
return $this->id->toRfc4122();
}
does not find any records.
public function __toString(): string
{
return $this->id->toBinary();
}
finds records on SQLite but does not find records on other database platforms.
Bug Report
Summary
When using UUIDs as keys in a SQLite database, the
ServiceEntityRepositoryProxy::find()
,findBy()
andfindOneBy()
methods convert a UUID to binary format when quering the database.When using
ServiceEntityRepositoryProxy::createQueryBuilder()
, the UUID is not converted to binary format and hence the DBAL query finds no records in the SQLite database.Current behavior
The same problem occurs with foreign keys. They work as expected in
find
methods and do not work as expected inQueryBuilder
.This issue is particularly problematic with foreign keys. With
->andWhere('c.id = :id')
you can manually convert theid
to binary in your app if the database platform is SQLite, but with->andWhere('c.user = :user')
you cannot.Symfony Profiler for Find
Symfony Profiler for QueryBuilder
Expected behavior
QueryBuilder
should also convert the UUID to binary format for SQLite queries.