I noticed the following the Symfony2 and Propel: if you have a form related to an entity, with subforms related to sub-entities that are linked in a 1 to many way, then the primary key is not propagated to sub element.
Eg: trying to insert your entity, it is ok but, when it saves your sub-entities (in a cascading way), the id of your entity (the foreign key) is not updated).
According to "http://ift.tt/1E3DbSa / Inserting A Related Row", with a 1 to many relationship, you must add sub-entities with the "add" method and not the "set".
If, before saving, I loop over all sub-entities and call the methods removeSubEntity then addSubEntity then it works well. So I suppose that, handling a request to map the form to the entity, Symfony2 uses the "set" method.
I can make it work using the "add"/"remove" but this is very dirty... Any idea ?
Aucun commentaire:
Enregistrer un commentaire