Question

I'm making fixtures and when I try to load them I have an error. The relationship between Award and Movie is unidirectional, so I load first Award because it hasn't any reference. The error says:

[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.

This is my Fixture class:

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;
    }
}
Was it helpful?

Solution

The problem is in line:

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

You can't pass an array as rererence. You probably wanted this instead:

$this->addReference("award-" . $i, $document);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top