tags:

views:

47

answers:

1

I have an Entity on Symfony that has also a file "attached" to it.

I want to save the file with the id of the created Entity.

The problem is, that I will know the Entity's ID only after doing "dosave()" on that Entity form.

Is there any way to save the file after doing the "dosave()" but still write the code as an override for the Entity's form code?

+1  A: 

Assuming you are using symfony's bundled file widget, then you can't do this, because of the way the form save process works. In short, the file is saved by the validator, but by the nature of it being a validator, the data hasn't been saved yet!

I've worked around this before by using a temporary filename for the file if the object is new, and then after save has completed (but still within an overload in the form class), move it to the real location now that you know the id.

benlumley
Subscribing, good point
Darmen