Production:
image_id
Image:
id
The ImageForm is embedded on the ProductionForm and the image is optional. The issue is that when adding an Image to an already existing Production via the embeddedForm and not changing any standard values in the Production form, the main form is not saved (Production has no changes).. except that its image_id needs updating.
I’m in two minds whether the problem is that I’ve incorrectly setup these forms or whether I need to add something into a save method binding.
Note this issue doesn’t occur if the production isNew i.e. you’re adding a new production and image all at once- or if you’re editing a production (i.e. changing its name another field) AND adding an image. Or if you’re editing an image that is already bound.
I understand loosely why this is occurring, and the order Symfony executes saves in forms.. but I don’t know what to add to make this work.
There’s not much code involved thus far, only what is found on the advanced forms jobeet; I’m using $this->embedRelation('Image'); and a post validator + saveEmbeddedForms override to avoid blank images being saved.
In summary: the problem is that if you are adding an image to a production that already exists without changing any values that are stored in the production table, the image is saved, but not related to the production, the image_id stored in the production table remains null.
I got this working with
$this->getObject()->setUpdatedAt(date('c'));.. a less hacky solution would be appreciated.