Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony & Doctrine getting a joined query to work
    primarykey
    data
    text
    <p>I've got an SQL query that returns all the rows in one table (country) which have a related entry in another table (ducks) but I'm struggling to turn this into DQL. This is a standard one-many relationship as each country can have multiple ducks, I believe it is all set up correctly as I can return ducks within a country and return the country a duck is in using standard code. </p> <p>The working query is:</p> <pre><code>SELECT c.* FROM country c INNER JOIN ducks d ON c.id = d.country_id GROUP BY c.country ORDER BY c.country ASC </code></pre> <p>I've tried converting this to:</p> <pre><code>SELECT c FROM WfukDuckBundle:Country c INNER JOIN WfukDuckBundle:Ducks d ON c.id = d.country_id GROUP BY c.country ORDER BY c.country ASC </code></pre> <p>which produces the following error:</p> <pre><code>[Semantical Error] line 0, col 79 near 'd ON': Error: Identification Variable WfukDuckBundle:Ducks used in join path expression but was not defined before. </code></pre> <p>I'm quite new to Symfony/Doctrine so I suspect it's probably something obvious!</p> <p>I'm using Symfony 2.0.11 with doctrine</p> <p>Update: I've Also tried:</p> <pre><code>SELECT c FROM WfukDuckBundle:Country c INNER JOIN c.ducks d ON c.id = d.country_id GROUP BY c.country ORDER BY c.country ASC </code></pre> <p>where 'ducks' is defined in the Country class as:</p> <pre><code>/** * @ORM\OneToMany(targetEntity="Ducks", mappedBy="country") */ protected $ducks; public function __construct() { $this-&gt;ducks = new ArrayCollection(); } </code></pre> <p>the definition for country in the ducks class is:</p> <pre><code>/** * @ORM\ManyToOne(targetEntity="Country", inversedBy="ducks") * @ORM\JoinColumn(name="country_id", referencedColumnName="id") */ private $country; </code></pre>
    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