symfony - Doctrine ManyToMany - join multiple relations -


I'm wondering if there is a way to get a record using multiple relationships from a table (to explain it With an example that is probably easy)

I have 3 models: There are many links between article, subject and type and article & lt; - & gt; Topics & Articles & lt; - & gt; The type and what I am looking at is to get the type of articles that have been assigned to the definitive subject. I hope this makes sense.

Below you can see the announcement of my institutions:

  class articles {/ ** * @ subject * * @ORM \ ManyToMany (targetEntity = "Topic") * @ORM \ JoinTable (name = "article_topic") * / protected $ topics; / ** * @ type type * * @ORM \ ManyToMany (targetEntity = "Type", invoked by = "article") * @ORM \ JoinTable (name = "article_type") * / protected $ types; } Article subject {/ ** * @ Article * * @ORM \ ManyToMany (targetEntity = "article") * / Private $ article; } Article type {** ** Articles * * @ORM \ ManyToMany (targetEntity = "article") * / Private $ article; }   

Now I have a way in my typewriter: (Updated)

  public function getByTopic ($ theme = void ) {$ Qb = $ this- & gt; getEntityManager () - & gt; CreateQueryBuilder () - & gt; Select ('t') - & gt; From ('type', 't'); ($ Theme) {$ subqb = $ this- & gt; getEntityManager () - & gt; CreateQueryBuilder () - & gt; Select ('a.id') - & gt; From ('paragraph', 'a') - & gt; Internal join ('a.topics', 'atop', 'with', 'atop.id =: topicId'); $ Qb- & gt; Inner Joen ('T. article', 'Ta') - & gt; ('Ta.id', $ subqb- & gt; getDql ()) (& gt; Setpaymator ('theme id', $ theme- & gt; in ($ qb-> expr () - & gt; GetId ());} $ qb-> GetQuery () -> GetResult ();}   

Return and get an error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected (But it's showing me line from the twig template and I'm struggling to get it at the bottom of it).

Why not doing something like this:

  $ qb = $ this-> getEntityManager () - gt; createQueryBuilder ('ty ') - & gt; Add sign (' t Y '); If ($ theme) {$ qb- & gt; join (' ty.articles', 'a') - & gt; select add ('a') - & gt; join ('a.topics' , 'To') - & gt; ('To.id =: topic_id') - & gt; Setpayeter ('topic_id', $ subject);} $ qb-> getQuery () -> getResult () Return;;    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -