As far as I know, fixtures will be loaded in given order, based on the value returned in getOrder()
method of each fixture files. Sharing Objects between Fixtures. For some reason, doctrine tries to load fixtures below in alphabetical order (class name) instead.
In example below, it has to load in Student, Subject and StudentSubject order however, it tries to load in Student, StudentSubject and Subject which causes problem because StudentSubject cannot exist before Student and Subject. Association: Student (1 -> N) StudentSubject (N <- 1) Subject
Any reason why this is happening?
class StudentFixtures extends AbstractFixture implements FixtureInterface
{
public function load(ObjectManager $manager)
{
......
$this->addReference('student-1', $student);
......
}
public function getOrder() { return 1; }
}
class SubjectFixtures extends AbstractFixture implements FixtureInterface
{
public function load(ObjectManager $manager)
{
......
$this->addReference('subject-1', $subject);
......
}
public function getOrder() { return 2; }
}
class StudetSubjectFixtures extends AbstractFixture implements FixtureInterface
{
public function load(ObjectManager $manager)
{
......
$student = $this->getReference('student-1');
$subject = $this->getReference('subject-1');
......
}
public function getOrder() { return 3; }
}
Error:
Bc-MacBook-Pro:sport bc$ app/console doctrine:fixtures:load --no-interaction --no-debug
> purging database
> loading Football\FrontendBundle\DataFixtures\ORM\StudentFixtures
> loading Football\FrontendBundle\DataFixtures\ORM\StudentSubjectFixtures
[OutOfBoundsException]
Reference to: (mba) does not exist
composer.json
"require-dev": {
"sensio/generator-bundle": "~2.3",
"doctrine/doctrine-fixtures-bundle": "2.2.0",
"doctrine/data-fixtures": "1.1.1"
},
Replace instances of FixtureInterface
with OrderedFixtureInterface
for example:
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
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