Я пытаюсь использовать построитель запросов, чтобы выбрать все категории, которые относятся к определенному superCategory
(category
и superCategory
имеют отношение многие ко многим).
Однако я не могу создать правильное предложение построителя запросов, потому что я не знаю, как ссылаться на superCategory
из моего category
, поскольку внутри идентификатора категории нет поля 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);