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?
$data = array()
instead of$data = null
in constructors? – smotttif($data == null) $data = array();
is before I work with$data
. But it is actually good point, I dont know why I usednull
as default value. – Zdeněk Topič