fixtures with self references
seems fixtures dump creates fixture in order that it can later not load:
$ app/console propel:fixtures:load --dir=fixtures/fixtures1 --connection=mds -vvv
No SQL fixtures found.
No XML fixtures found.
[2014-09-19 15:08:15] app.INFO: DELETE FROM `customer` [] []
[2014-09-19 15:08:15] app.INFO: DELETE FROM `customer` [] []
array(0) {
}
string(34) "MDS\\Model\\Customer_Customer_552882"
[Propel] Exception
The object "Customer_552882" from class "\MDS\Model\Customer" is not defined in your data file.
$ cat fixtures/fixtures1/test.yml
\MDS\Model\Customer:
Customer_4389:
state: active
merged_id: Customer_552882
created: '1402224114'
last_modified: '1402224114'
Customer_552882:
state: active
created: '1407191043'
last_modified: '1407191043'
if i swap items order, then it starts to work, i.e problem with self references
seems similar problem exist if it tries to delete whole table, for example after the fixture has been loaded, load it again:
[2014-09-20 13:22:21] app.INFO: DELETE FROM `customer` [] []
[2014-09-20 13:22:21] app.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`mds`.`customer`, CONSTRAINT `customer_fk_31a814` FOREIGN KEY (`merged_id`) REFERENCES `customer` (`id`)) [] []
my proposals:
- try to reorder dump so that items that are being referenced are declared first
- load whole "table" and then verify the relations
as it's not always possible to reorder items so they are declared first before being used (if more complex relations are used)
the second problem with delete from table can be hacked to reset merged_id before fixture load:
update customer set merged_id=null;
but that's complicated, so instead maybe disable FK checks, like mysqldump does:
START TRANSACTION;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
DELETE FROM `customer`;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
Although there's no Propel 1/2 adapter yet for https://github.com/nelmio/alice, I'm considering rather to throw out our fixtures loader and reference to the more powerful fixtures loader of nelmio. Writing a Adapter for Propel in Alice would be easy. WDYT @propelorm/propel ? Would be a maintainance less and we have a better fixtures loader to show.
+1 on the adapter.
:+1: alice is awesome and having less classes in propel would be a great thing.
:+1: great idea
Is someone able to make a PR here with suggested changes?