0

我正在制作固定装置,当我尝试加载它们时出现错误。奖项和电影之间的关系是单向的,所以我加载第一个奖项,因为它没有任何参考。错误说:

[Symfony\Component\Debug\Exception\ContextErrorException] Warning: spl_object_hash()
expects parameter 1 to be object, array given in
/Users/benatespina/Development/filmboot.web/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM‌/MongoDB/UnitOfWork.php line 1706.

这是我的夹具类:

namespace MyProject\MovieBundle\DataFixtures\MongoDB;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

use MyProject\MovieBundle\Document\Award;

class Awards extends AbstractFixture implements OrderedFixtureInterface {
    public function load(ObjectManager $manager) {
        $awards = array(
            array(
                "name"     => "Sitges",
                "year"     => "1992",
                "category" => "Best director"
        );

        foreach ($awards as $i => $award) {
            $document = new Award();
            $document->setName    ($award["name"]);
            $document->setYear    ($award["year"]);
            $document->setCategory($award["category"]);

            $manager->persist($document);
            $this->addReference("award-" . $i, $award);
        }

        $manager->flush();
    }

    public function getOrder() {
        return 1;
    }
}
4

1 回答 1

2

问题在于:

$this->addReference("award-" . $i, $award);

您不能将数组作为参考传递。你可能想要这个:

$this->addReference("award-" . $i, $document);
于 2013-11-13T10:33:49.950 回答