Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine2: how to solve left join not being generated
    primarykey
    data
    text
    <p>consider these two entities:</p> <pre><code>/** @Entity */ class String { /** @Id @Column(type="integer") * @GeneratedValue */ public $id; /** @Column(length=255) */ public $name; /** * @OneToMany(targetEntity="StringTranslation", mappedBy="owner") */ public $translations; } /** @Entity */ class StringTranslation { /** @Id @Column(type="integer") * @GeneratedValue */ public $id; /* @ManyToOne(targetEntity="String", inversedBy="translations") * @JoinColumn(name="foreignId", referencedColumnName="id") */ public $owner; /** @Column(length=2) */ public $lang; /** @Column(length=255) */ public $translation; } </code></pre> <p>When I get the query using</p> <pre><code>$query = qb()-&gt;select(array('s', 't')) -&gt;from('String', 's') -&gt;leftJoin('s.translations', 't') -&gt;getQuery() -&gt;getSQL(); </code></pre> <p>I get this result:</p> <blockquote> <p>SELECT s0_.id AS id0, s0_.name AS name1, s1_.id AS id2, s1_.foreign_id AS foreign_id3, s1_.lang AS lang4, s1_.translation AS translation5 FROM String s0_ LEFT JOIN</p> </blockquote> <p>Why is the left join not being generated?</p> <p>When i try to get the result of the query with</p> <pre><code>$query = qb()-&gt;select(array('s', 't')) -&gt;from('String', 's') -&gt;leftJoin('s.translations', 't') -&gt;getQuery() -&gt;getArrayResult(); </code></pre> <p>this error comes up:</p> <blockquote> <p>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax</p> </blockquote> <p>How can this problem be solved?</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.
 

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