Search code examples
symfony1symfony-1.4symfony-forms

How to get the last inserted id of embed form and store it in parent form : symfony


I have to parent form called EventForm and embed form called as RegisterForm. If your is not logged in means i want to show register form. Registration working fine with embed form. But after registration i want to store user id to parent table event.

I guess saveEmbeddedFroms() function called after parent form saved. So which function is suitable to update parent form. Can any one give me idea. How to do this.


Solution

  • When you call $form->save() on a form it saves the embedded forms as well but the embedded forms are saved after the main object.

    I think what you could do is to write a preSave() function for your main form in which yu can get the embedded form, perform a save() o it (which will give you in return the saved object) and manually set the userid in the main form (remember to unset the embedded form so it is not saved twice).

    You could also rethink the whole model because it looks a bit complicated ;) Do you reaaly have to use embedded forms here?