Search code examples
symfonycollectionspropelpropel2

Propel2 collections disappear on update


My colleagues and I have written a dozen web applications using Symfony2 and Propel1. We are now trying to use Propel2 but encounter the following problem when migrating an application from Propel1 to Propel2.

In our simple schema, a parent object, Auteur (author) possesses a collection of children Livre (book) objects. We use a Symfony form to create the Auteur with a collection of Livres objects. In this case, the Auteur and Livres are correctly persisted in the database.

However, when we update the Auteur object without touching the collection of Livres, the collection is emptied.

We could not determine whether this was a bug in Propel2 (or less probably Symfony2) or if we are doing things incorrectly. The almost same code (somewhat adapted to Propel1) works without a problem: the Livres collection is not emptied on Auteur update.

We have published a minimal project reproducing the problem. To test it with Propel2, please do:

git clone https://github.com/spyrit/MinimalS2P2.git
cd MinimalS2P2
composer install
app/console propel:build
app/console propel:migration:diff
app/console propel:migration:migrate

To test it with Propel1, use to the propel1 branch:

git checkout propel1
composer install
app/console propel:build
app/console propel:migration:generate-diff
app/console propel:migration:migrate

We will be grateful on any hint concerning this issue.


Solution

  • The approach was correct, but there was a bug in Propel2 that caused this issue.

    It was fixed in https://github.com/propelorm/Propel2/pull/1027