Some helping hands when working with embedded doctrine relations in symfony forms
Many of you will have been confronted with the symfony form sub-framework at some point. And when you had to work with model relations that were a tad more complicated that the examples from the documentation you will have experiences difficulties. I know I have. There are however three interesting plugins that can be of great help.
Let me start with the most simple one of them.
This is one my own plugins and provides a single and very simple functionality for one-to-many relations. It provides a widget that you can use on the column that contains the foreign key.
You will then get a JQuery powered widget that lets you choose from existing objects to be related using autocomplete search. You can delete a relation and you can add one on the fly with a JQuery modal dialogue.
See my older post for more detailed information.
This plugin provides much more functionality that the first plugin. To use it your forms have to inherit from a form class included in the plugin. It overloads the embedRelation() method which you can use to add, change and delete relations.
It will change your form markup to include a UI for all these interactions. This plugin is highly configurable which unfortunately can result in misconfiguration and spending a few moments to figure out the correct options for your requirement.
Once set up though it will work like a charm.
Update: this is no longer recommended. See comments for details!
See also Kris Wallsmith’ talk on symfony day 2010 (slides 86-103) for more info.
I hope this saves somebody a few headaches. 😉