我有一个语法错误的查询。这是错误!
string(63)“ [语法错误]第0行,列57:错误:预期文字,有'd'“
public function getDomain(string $country)
{
try {
return $this->createQueryBuilder('d')
->where(':country NOT IN (d.blocked_countries)')
->setParameter('country', $country)
->setMaxResults(1)
->getQuery()
->getSingleResult()
;
} catch (\Exception $exception) {
return $exception->getMessage();
}
}
在这种情况下,我们无法应用IN
运算符,因为主义将array type
作为字符串存储在php serialize()
中。所以你可以做这样的事情
$qb = $this->createQueryBuilder('d');
$qb
->where(
$qb->expr()->like('d.blocked_countries', "'%$country%'")
)
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
;