PathExpression无效。 StateFieldPathExpression或SingleValuedAssociationField预期 [英] Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected
本文介绍了PathExpression无效。 StateFieldPathExpression或SingleValuedAssociationField预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下查询:
$query = $em->createQueryBuilder()->select('s', 'COUNT(pictures) AS HIDDEN items')
->from("MainBundle:InstagramShop", 's')
->innerJoin('s.userPictures', 'pictures')
;
$query->andWhere('s.id > :shopId');
$query->andWhere('pictures.style = :style');
$query->andHaving('items >= 4');
由于某种原因,它会给我以下错误:
and for some reason it gives me the following error:
[Semantical Error] line 0, col 151 near 'style = :style': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.
我有一个InstagramShop与InstagramShopPictures有很多关系:
I have an InstagramShop which has a many to one relationship with InstagramShopPictures:
这是实体:
class InstagramShopPicture
{
/**
* @Exclude()
* @ORM\OneToMany(targetEntity="App\MainBundle\Entity\InstagramPictureStyle",
mappedBy="picture", cascade={"persist","remove"})
*/
protected $style;
/**
* @Exclude()
* @ORM\ManyToOne(targetEntity="InstagramShop", inversedBy="userPictures")
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
protected $shop;
}
这里的InstagramShop
and here's InstagramShop
class InstagramShop
{
/**
* @Exclude()
* @ORM\OneToMany(targetEntity="InstagramShopPicture", mappedBy="shop", cascade={"persist"})
* @ORM\OrderBy({"created" = "DESC"})
*/
protected $userPictures;
}
任何想法为什么?
推荐答案
今天,当我正在寻找完全相同的错误消息时,我发现了你的问题,也与使用COUNT()相关。 Pieter Vogelaar让我以下列方式解决:
Today I found your question when I was looking for the exact same error message, also related to using COUNT(). Pieter Vogelaar helpt me to solve it the following way:
$qb = $this->createQueryBuilder('c', 'bc')
->select('c')
->leftJoin('c.books', 'bc')
->addSelect('COUNT(bc.id) AS book_count')
->where('c.owner = :user')->setParameter(':user', $user)
->groupBy('c.id')
->orderBy('c.created');
您可能需要写:
COUNT(pictures.id)而不是COUNT )
You probable need to write: COUNT(pictures.id) instead of COUNT(pictures)
这篇关于PathExpression无效。 StateFieldPathExpression或SingleValuedAssociationField预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文