title: find the children of an object in the database
body: <p>I have an entity account which is a classic entity with children and parents. The way I did it, the SQL relation is identified only with the parents. </p>
  
  <p>What I want is to have for each object the list of its children.</p>
  
  <p>In plain old PHP, I would simply loop on a  mysql_fetch_array to have all my accounts, and for each one request again to the DB where parent = id so and put that in the property children (array) of my account object.</p>
  
  <p>In Symfony2/doctrine, it seems I cannot do that, at least not that simply.</p>
  
  <p>How am I gonna do then ?</p>
  
  <p><strong>edit:</strong>
  In my controller this is what I would like to do:</p>
  
  <pre><code>  $COA = $this-&gt;getDoctrine()-&gt;getRepository('NRtworksChartOfAccountsBundle:Account')-&gt;findAll();
  
     foreach($COA as $one_account)
     {
         echo $one_account.getChildren();
  
     }
  </code></pre>
  
  <p>But that doesn't work. When I pass this $COA to my twig I can loop on it but not in the PHP.</p>
  
  <pre><code>&lt;?php
  namespace NRtworks\ChartOfAccountsBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  
  
  /**
  * @ORM\Entity
  * @ORM\Table(name="Account")
  */
  
  class Account
  {
  /**
  * @ORM\Id
  * @ORM\Column(type="integer")
  * @ORM\GeneratedValue(strategy="AUTO")
  */
  
  protected $id;
  
  /**
  * @ORM\Column(type="string", length=100, unique = true)
  */
  
  protected $name;  
  
  /**
  * @ORM\Column(type="string", length=50)
  */
  
  protected $code;
  
  /**
  * @ORM\OneToMany(targetEntity="Account", mappedBy="parent")
  */
  
  private  $children;
  
  /**
  * @ORM\ManyToOne(targetEntity="Account", inversedBy="children")
  */
  
  private $parent;
  
  
  public function __construct()
  {
      $this-&gt;children = new ArrayCollection();
  }
  
  //getter &amp; setter    
  
  ?&gt;    
  </code></pre>