0

In my document I have a category member attribute which is referenced to the same class Category

/**
 * Parent Category's path ( Indexed )
 *
 * @var String
 * @MongoDB\ReferenceOne( targetDocument = "Category", simple="true" )
 */
protected $parent;

Now inside my form I want to make parent a select dropdown field and show all my categories in that

$builder->add( 'parent', 'choice', array(                                                                                        
    'choices' => array( '..', '..' )
));                                                                                                               

How do I show all my categories in dropdown and map that dropdown field so when form is submitted the parent field contains object ID of parent field

tomas.pecserke
  • 3,260
  • 25
  • 26
aditya
  • 996
  • 2
  • 12
  • 25

1 Answers1

1

Use document field type:

$builder->add('parent', 'document', array(
    'class' => 'AcmeDemoBundle:Category',
    'property' => 'name_of_property_to_display_as_item_label',
));
tomas.pecserke
  • 3,260
  • 25
  • 26