I desperately try to load Doctrine fixtures into my DB. When I call the global cli load function, nothing looks bad at the beginning:
> purging database
> loading [1] namespace_of_my_first_fixture_file
> loading [2] namespace_of_my_second_fixture_file
...
But it fails in the middle of the process when it tries to re-use an object from a previous loaded fixtures (wrong index):
[ErrorException]
Notice: Undefined index: my_object_index in /Users/Swop/project/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php line 145
I look at the DB and nothing is inserted, in any tables. If I try to load only the first fixture (which seems to be loaded according to the above paste), I've got an error:
[InvalidArgumentException]
Could not find any fixtures to load in:
- src/MyOrg/MyBundleBundle/DataFixtures/ORM/MyFirstFixtureFileData.php
By the way, I just run that on my MacOS X (Mountain Lion) with a self-compiled PHP 5.4 instance.
The fixtures data loading works well on my Linux box.
I could not find a good example in the docs and finally found that this works. Just use the folder location and do not specify the fixture file.
doctrine:fixtures:load --fixtures=src/MyOrg/MyBundleBundle/DataFixtures/ORM --append
Take a look at the DoctrineFixturesBundle documentation.
Your data fixture classes need to implement OrderedFixtureInterface
so they are loaded in a pre-set order.
You can then setup references with $this->addReference('ref-name', $variable)
and refer to those references in another fixture with $this->getReference('ref-name')
.
My guess as to why it seemed to work on your linux box is because the fixures were loaded in a different order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With