symfony2 adjacency list model use with Forms
I have a self referencing table as covered in the doctrine documentation (which is already in heavy use throughout the application and therefore changing to nested tree isn't a current option). 

[http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html#one-to-many-self-referencing][1] 

The table structure looks like this:

    +----+----------+--------+
    | id | parentID |  Name  |
    +----+----------+--------+
    |  1 |     null | Name 1 |
    |  2 |        1 | Name 2 |
    |  3 |        1 | Name 3 |
    |  4 |        2 | Name 4 | 
    |  5 |        1 | Name 5 |
    --------------------------

Up until now in our forms we've been using the entire entities content our form, ie

            $builder->add('hierarchyid', 'entity', array(
                'class' => 'AcmeTestBundle:Hierarchies')                

Which works fine, but now I want to be able to amend this to set points in the table, ie something like:

            ->add('hierarchyid', 'entity', array(
                'class' => 'AcmeTestBundle:HierarchiesTest',
                'query_builder' => function(HierarchiesTestRepository $repo)
        {return $repo->findAllById('2');}

But I've hit a mental block how to complete this, any ideas?

One option I've considered is I already have code that builds an array collection of these entities, which is used elsewhere, but I'm unfamiliar with how I should go about implement a doctrine arraycollection in a form type.

    private function createNodeArray($node) 
    {
        $this->hierarchyArrayCollection->add($node);
        foreach ($node->getChildren() as $hierarchy)
        {
           $this->createNodeArray($hierarchy);
        }        
    }


  [1]: http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html#one-to-many-self-referencing
symfony2 adjacency list model use with Forms
===

I have a self referencing table as covered in the doctrine documentation (which is already in heavy use throughout the application and therefore changing to nested tree isn't a current option). 

[http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html#one-to-many-self-referencing][1] 

The table structure looks like this:

    +----+----------+--------+
    | id | parentID |  Name  |
    +----+----------+--------+
    |  1 |     null | Name 1 |
    |  2 |        1 | Name 2 |
    |  3 |        1 | Name 3 |
    |  4 |        2 | Name 4 | 
    |  5 |        1 | Name 5 |
    --------------------------

Up until now in our forms we've been using the entire entities content our form, ie

            $builder->add('hierarchyid', 'entity', array(
                'class' => 'AcmeTestBundle:Hierarchies')                

Which works fine, but now I want to be able to amend this to set points in the table, ie something like:

            ->add('hierarchyid', 'entity', array(
                'class' => 'AcmeTestBundle:HierarchiesTest',
                'query_builder' => function(HierarchiesTestRepository $repo)
        {return $repo->findAllById('2');}

But I've hit a mental block how to complete this, any ideas?

One option I've considered is I already have code that builds an array collection of these entities, which is used elsewhere, but I'm unfamiliar with how I should go about implement a doctrine arraycollection in a form type.

    private function createNodeArray($node) 
    {
        $this->hierarchyArrayCollection->add($node);
        foreach ($node->getChildren() as $hierarchy)
        {
           $this->createNodeArray($hierarchy);
        }        
    }


  [1]: http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html#one-to-many-self-referencing