Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:24:37+00:00 2026-06-01T20:24:37+00:00

I have a self referencing table as covered in the doctrine documentation (which is

  • 0

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

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->findBy??????}

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:24:38+00:00Added an answer on June 1, 2026 at 8:24 pm

    For anyone interested the solution I went with in the end was to generate an array and use choice field type rather than entity,such as this:

    ->add('hierarchyid', 'choice', array(
                   'choices' => $hierarchy)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a self referencing table named categories that has a parentcategoryid column that
I have a self referencing table in Oracle 9i, and a view that gets
I have a self-referencing table 'comments' where comments.replyToId REFERENCES comments.ID. My question is, how
I have a table which has a foreign key referencing itself. This would be
I have a standard self referencing table of Categories . In my entity model
I have a table that has an Self referencing relationship - One Wall comment
I have a self-referencing table with an Id, CategoryName, and ParentId. It's a typical
I have a self-referencing table (Customers) and a table that will link to one
I have implemented a linked list as a self-referencing database table: CREATE TABLE LinkedList(
I have a typical self-referencing table of employees. How can you build an UDF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.