gpt4 book ai didi

symfony - Doctrine 固定装置不会按给定顺序加载,而是按字母顺序加载

转载 作者:行者123 更新时间:2023-12-02 17:00:01 24 4
gpt4 key购买 nike

据我所知,装置将根据getOrder()中返回的值按给定顺序加载。每个夹具文件的方法。 Sharing Objects between Fixtures 。由于某种原因,学说尝试按字母顺序(类名)加载下面的装置。

在下面的示例中,它必须按 Student、Subject 和 StudentSubject 顺序加载,但是,它尝试按 Student、StudentSubject 和 subject 加载,这会导致问题,因为 StudentSubject 不能存在于 Student 和 subject 之前。协会:Student (1 -> N) StudentSubject (N <- 1) Subject

发生这种情况的原因是什么?

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; }
}

错误:

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"
},

最佳答案

FixtureInterface 的实例替换为 OrderedFixtureInterface

例如:

使用 Doctrine\Common\DataFixtures\OrderedFixtureInterface;

关于symfony - Doctrine 固定装置不会按给定顺序加载,而是按字母顺序加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30688317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com