Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery builder join on many to many relationship
    primarykey
    data
    text
    <p>I am trying to use query builder to select all the categories that belong to a certain superCategory (category and superCategory have a many to many relationship). However, I am unable to build a correct query builder sentence because I don't know how to reference to the superCategory from my category as there is no superCategory field inside my category ID.</p> <p>The objects in the database look like :</p> <pre><code>Category: id name SuperCategory id name categories_superCategories id category_id superCategory_id </code></pre> <p>Here are the definition of my objects (yml files ) :</p> <pre><code>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 </code></pre> <p>and</p> <pre><code>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 </code></pre> <p>How would I build a query builder sentence to get the categories that belong to a certain superCategory ?</p> <p>The query inside my CategoryRepository :</p> <pre><code>$this-&gt;createQueryBuilder('c') -&gt;innerJoin( ?????? ) -&gt;setParameter('superCategoryName', $superCategoryName); </code></pre> <p>Thank you...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload