我有一个与Image实体存在ManyToMany关系的实体Image。我试图在内部联接请求中获取与我从数据库中获取的标签相关的图像,如下所示:
public function findOneByNameWithImages(string $name)
{
return $this->createQueryBuilder('t')
->addSelect('t.images')
->leftJoin('t.images', 'images')
->where('t.name = :name')
->setParameter('name', $name)
->getQuery()
->getResult();
}
但是当我执行查询时,出现此错误:
[Semantical Error] line 0, col 12 near 'images FROM App\Entity\Tag':
Error: Invalid PathExpression. Must be a StateFieldPathExpression.
答案 0 :(得分:0)
解决方案是将选择添加到别名图像而不是t.images:
public function findOneByNameWithImages(string $name)
{
return $this->createQueryBuilder('t')
->leftJoin('t.images', 'images')
->addSelect('images')
->where('t.name = :name')
->setParameter('name', $name)
->getQuery()
->getResult();
}