I'm using Symfony2 with Mongodb. I have two documents (objects), User and Country. The country document is embedded into the user document :
/**
* @MongoDB\EmbeddedDocument
*/
class Country
and my user document :
/**
* @MongoDB\EmbedOne(targetDocument="Country")
*/
protected $country;
I have my country formType embedded into my user form type as follow:
UserFormType :
$builder->add('country', new CountryType())
And CountryType :
$builder->add('libelle', 'document', array(
'label' => false,
'class' => 'ELCoreBundle:Country',
'property' => 'libelle',
));
In my controller :
$form = $this->createForm(new UserFormType(), $user);
[...]
return array('edit_form' => $form->createView());
And my template :
{{ form_errors(edit_form.country) }}
{{ form_widget(edit_form.country) }}
The form is well rendered, with all my countries libelle as html and countries id as value in the dropdownlist. On the save action, the document country is embedded into the user as expected :
[...]
"country": {
"_id": ObjectId("5494357b84114f7b067b23d7"),
"libelle": "Argentina"
}
[...]
My problem is, when i reload the form, the dropdownlist select the first country, not the one i have in my user object. So my question is : How can i set the 'selected' tag on the country associated to my user ?