1
votes

My entities look like this (pasting just relevant parts):

User.php

    /**
     * @ManyToMany(targetEntity="Startup", inversedBy="members", cascade={"persist"})
     * @OrderBy({"name"="ASC"})
     * @var Startup[]
     */
    private $startups;

    public function __construct($data = array()) 
    {
        $this->startups = new ArrayCollection();
        $this->joined = new DateTime("now");
        parent::__construct($data);
    }

Startup.php

    /**
     * @ManyToOne(targetEntity="User", cascade={"persist"})
     * @var User
     */
    private $founder = null;

    /**
     * @ManyToMany(targetEntity="User", mappedBy="startups", cascade={"persist"})
     * @OrderBy({"lastName" = "ASC"})
     * @var User[]
     */
    private $members;

    public function __construct($data = array())
    {
        $this->files = new ArrayCollection();
        $this->topics = new ArrayCollection();
        $this->members = new ArrayCollection();

        $this->founded = new DateTime("now");

        parent::__construct($data);
    }

Now with those I am running this code ($this->identity instanceof User, $values is just some struct filled with strings, $this->model is EntityManager):

          $startup = new Startup();
          $startup->name = $values->name;
          $startup->founder = $this->identity;
          $this->model->persist($startup);
          $this->identity->startups[] = $startup;
          $this->model->flush();

And I get this:

Argument 1 passed to Doctrine\ORM\UnitOfWork::getCollectionPersister() must be an array, null given, called in .../libs/Doctrine/ORM/UnitOfWork.php on line 332 and defined

Triggered on flush obviously. What have I got wrong?

1
Have you tried $data = array() instead of $data = null in constructors?smottt
Thats not issue, I got it covered, I already removed it from post to make it more clear. if($data == null) $data = array(); is before I work with $data. But it is actually good point, I dont know why I used null as default value.Zdeněk Topič
Are you able to: 1. Provide a better stack trace (complete one, eventually with passed in parameters) 2. tell us why your model has persistence methods?Ocramius
Call stack is in the question now. Model is just helper class to make access to repositories and EM core methods easier.Zdeněk Topič
@ZdeněkTopič can you now please try to run schema tool validation? It's a CLI tool. Not sure if it's integrated with Nette though.Ocramius

1 Answers

1
votes

Fixed. $this->identity was problem. Framework got it serialized and then unserialized.