public function load(ObjectManager $manager) { foreach ($this->groups as $groupName) { $groupObject = new AccountGroup(); $groupObject->setName($groupName); $manager->persist($groupObject); $this->addReference('client-account-group-' . $groupName, $groupObject); } foreach ($this->types as $key => $item) { $typeObject = new AccountType(); $typeObject->setName($item['name']); $manager->persist($typeObject); $this->addReference('client-account-type-' . ($key + 1), $typeObject); foreach ($item['groups'] as $groupKey) { $groupTypeObject = new AccountGroupType(); $groupTypeObject->setGroup($this->getReference('client-account-group-' . $groupKey)); $groupTypeObject->setType($this->getReference('client-account-type-' . ($key + 1))); $manager->persist($groupTypeObject); $this->addReference('client-account-group-type-' . $groupKey . '-' . ($key + 1), $groupTypeObject); } } $manager->flush(); }