Alice has given away the persistence layer in 3.x.
In the attempt of migrating from 2.2 to 3.0.x, …
I need to load and persist some fixtures first (so their id
get populated) and then reference those entities ids from another bunch of fixture files.
How can this be achieved ?
I guess I may have to loop and load multiple fixture files sets separately but I have no idea how objects references will subsist in such scenario.
My setup currently doesn't work but causes the following error to prompt:
Invalid value given for the property "fooDbId" of the object "bar1" (class: Doctrine\Model\Bar).
My FixturesLoader.php:
// …
use Nelmio\Alice\Loader\NativeLoader as AliceLoader;
// …
$loader = new AliceLoader();
$entities = $loader
->loadFiles(
[
__DIR__.'/foo.yml',
/* ↓ Some more fixture files ↓ */,
# Here comes "bar" which references persisted foo entities id
# through its "fooDbId" property using expresion '@foo1->id'
__DIR__.'/bar.yml'
],
['locale' => 'en_EN']
)
->getObjects();
foreach ($entitites as $entity) {
$manager->persist($entity)
}
$manager->flush();
bar.yml :
Doctrine\Model\Bar:
bar1:
fooDbId: '@foo1->id'
# ↓ More properties ↓
Edit
fooDbId
is not a "real" relation/foreign-key field but the 0
left-padded Foo entity id. (Bar::setFooDbId is in charge of the left-padding operation). Ex: given a Foo instance with an id property value of 87
, the associated Bar instance should have its fooDbId
property equal to '00000087'.
Thank you.