1

我的实体看起来像这样(仅粘贴相关部分):

用户.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);
    }

启动.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);
    }

现在,我正在运行这段代码($this->identity instanceof User,$values 只是一些用字符串填充的结构,$this->model 是 EntityManager):

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

我明白了:

传递给 Doctrine\ORM\UnitOfWork::getCollectionPersister() 的参数 1 必须是一个数组,给定 null,在第 332 行的 .../libs/Doctrine/ORM/UnitOfWork.php 中调用并定义

显然是在冲洗时触发的。我做错了什么?

4

1 回答 1

1

固定的。$this->identity是问题。框架将其序列化然后反序列化。

于 2013-01-07T22:44:15.210 回答