Doctrine: Cannot select entity through identification variables without choosing at least one root entity alias

后端 未结 1 683
感动是毒
感动是毒 2020-12-06 09:41

I\'m using the following code in the query builder, to select an average of score values, and the category entity to which that average belongs:

<         


        
相关标签:
1条回答
  • 2020-12-06 10:16

    createQueryBuilder() can only take a parameter when it is called from the repository of the matching entity. In case you do not call it from this repository you should define a from method.

    ->from('YourMappingSpace:Campsite', 's')
    

    Passing a parameter to createQueryBuilder() is for conveniance anyway. You can always define it manually. The function looks like this (Only inside the entity repository):

    public function createQueryBuilder($alias)
    {
        return $this->_em->createQueryBuilder()
            ->select($alias)
            ->from($this->_entityName, $alias);
    }
    
    0 讨论(0)
提交回复
热议问题