我正在尝试使用查询生成器来选择属于某个特定superCategory
(category
并且superCategory
具有多对多关系)的所有类别。
但是,我无法构建正确的查询构建器语句,因为我不知道如何引用superCategory
from my ,因为我的类别 IDcategory
中没有字段。superCategory
数据库中的对象如下所示:
Category:
id
name
SuperCategory
id
name
categories_superCategories
id
category_id
superCategory_id
这是我的对象(yml 文件)的定义:
YOP\YourOwnPoetBundle\Entity\TraitCategory:
type: entity
repositoryClass: YOP\YourOwnPoetBundle\Repository\TraitCategoryRepository
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: '255'
lifecycleCallbacks: { }
manyToMany:
superCategories:
targetEntity: SuperCategory
joinTable:
name: traitCategories_superCategories
joinColumns:
traitCategory_id:
referencedColumnName: id
inverseJoinColumns:
superCategory_id:
referencedColumnName: id
和
YOP\YourOwnPoetBundle\Entity\SuperCategory:
type: entity
repositoryClass: YOP\YourOwnPoetBundle\Repository\SuperCategoryRepository
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: '255'
lifecycleCallbacks: { }
manyToMany:
msgCategories:
targetEntity: MsgCategory
mappedBy: superCategories
traitCategories:
targetEntity: TraitCategory
mappedBy: superCategories
我将如何构建一个查询构建器语句来获取属于某个特定的类别superCategory
?
我里面的查询CategoryRepository
:
$this->createQueryBuilder('c')
->innerJoin( ?????? )
->setParameter('superCategoryName', $superCategoryName);