无法通过存储库中的标识变量选择实体 [英] Cannot select entity through identification variables in repository
本文介绍了无法通过存储库中的标识变量选择实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下查询。查询在我的InstagramShopPicture内部
I have the following query. The query is inside my InstagramShopPicture
$queryBuilder = $this->createQueryBuilder('p')
->select('p.id, p.caption, p.price, p.lowresimageurl, p.medresimageurl, p.highresimageurl, p.numberoflikes, p.numberofdislikes, shop.id, shop.username, shop.fullname, contact, category')
->leftJoin('p.shop', 'shop')
->leftJoin('shop.contact', 'contact')
->leftJoin('p.category', 'category')
->leftJoin('category.pictureTopCategory', 'pictureTopCategory')
->leftJoin('category.pictureFirstLevelCategory', 'pictureFirstLevelCategory')
->leftJoin('category.pictureSecondLevelCategory', 'pictureSecondLevelCategory')
->where('p.isLocked = false')
->andWhere('p.isStyleInspiration = false')
->andWhere('shop.isLocked = false');
但是我遇到以下错误:
QueryException: [Semantical Error] line 0, col -1 near 'SELECT p.id,': Error: Cannot select entity through identification variables without choosing at least one root entity alias
如何解决此问题的任何想法?
any idea on how to solve this?
推荐答案
在SO中进行了一些研究之后,我来到了这个解决方案。尝试添加
After some research here in SO I came to this solution. Try adding
->from('YourEntityNameForP', 'p')
->from('YourEntityNameForShop', 'shop')
到 createQueryBuilder
由于我既不熟悉Symfony 2,也不熟悉Doctrine 2,只是想提供帮助!
Since I'm not familiar neither with Symfony 2, nor with Doctrine 2 and just trying to help!
此处的信用:原则:如果不选择至少一个根实体别名,则无法通过标识变量选择实体
这篇关于无法通过存储库中的标识变量选择实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文