From 1d774b19e8637c9f027e08d2d7cbfc554b9c74f8 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 1 Nov 2021 16:00:48 +0100 Subject: [PATCH] datafixture relationship: attempt --- .../DataFixtures/ORM/LoadPeople.php | 4 ++++ .../DataFixtures/ORM/LoadRelationships.php | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php index adc37d5b5..f69ec0303 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php @@ -106,6 +106,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con protected UserRepository $userRepository; + public const PERSON = 'person'; + public function __construct( Registry $workflowRegistry, SocialIssueRepository $socialIssueRepository, @@ -257,6 +259,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con $manager->persist($person); $manager->persist($accompanyingPeriod); echo "add person'".$person->__toString()."'\n"; + + $this->addReference(self::PERSON, $person); } private function getRandomUser(): User diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadRelationships.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadRelationships.php index cfabde912..5efc68400 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadRelationships.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadRelationships.php @@ -6,17 +6,31 @@ namespace Chill\PersonBundle\DataFixtures\ORM; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Persistence\ObjectManager; +use Chill\PersonBundle\DataFixtures\ORM\LoadPeople; +use Chill\PersonBundle\DataFixtures\ORM\LoadRelations; +use Chill\PersonBundle\Entity\Relationships\Relationship; class LoadRelationships extends Fixture implements DependentFixtureInterface { + + + public function getDependencies() { + return [ + LoadPeople::class, + LoadRelations::class + ]; } public function load(ObjectManager $manager) { - + $relationship = new Relationship; + $relationship->setFromPerson($this->getReference(LoadPeople::PERSON)); + $relationship->setToPerson($this->getReference(LoadPeople::PERSON)); + $relationship->setRelation($this->getReference(LoadRelations::RELATIONS)); + $relationship->setReverse((bool)random_int(0, 1)); } } \ No newline at end of file