Php 是否有一种方法可以使用ZF2表格在条令中同时插入引用新实体的多个实体?

Php 是否有一种方法可以使用ZF2表格在条令中同时插入引用新实体的多个实体?,php,doctrine-orm,zend-framework2,Php,Doctrine Orm,Zend Framework2,我有一个Product实体和一个ProductImage实体。产品图像为“manytone”,包含产品的参考字段 我正在使用Zend Framework 2表单模块,其中包含图像的“Collection”字段集。表单将填充数据库中手动添加的行,但不会创建新行或删除它们 product image collection字段集包含图像的id、url和排序字段 当我提交带有新数据的表单时,DoctrineObject或试图基于标识符加载ProductImage实体,但ProductImage.id为空

我有一个
Product
实体和一个
ProductImage
实体。产品图像为“manytone”,包含产品的参考字段

我正在使用Zend Framework 2表单模块,其中包含图像的“Collection”字段集。表单将填充数据库中手动添加的行,但不会创建新行或删除它们

product image collection字段集包含图像的id、url和排序字段

当我提交带有新数据的表单时,DoctrineObject或试图基于标识符加载ProductImage实体,但
ProductImage.id
为空,因为没有实体可供参考

我尝试创建自己的文档,或者扩展DoctrineObject,如果实体不存在,则创建实体,但问题是,在创建之前,产品还没有可引用的ID


我的问题是我是否需要对图像进行完全定制?或者有没有办法使用DoctrineObject Hyderator来实现这一点?

如果这对您有效,我不是舒尔,但我认为我有一个类似的概念,一个域有一个属性表(一个域有多个属性)

请注意我在
Domain->addProperty()
中设置属性的域id的代码(如果域没有id,这也可以使用)

希望这有帮助:)

这是我的
域的代码

<?php
/**
 * Created by PhpStorm.
 * User: Richard
 * Date: 30.11.2014
 * Time: 13:24
 */
namespace Common\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Common\Entity\Property;

/**
 * @ORM\Entity
 * @ORM\Table(name="domain")
 */
class Domain {
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer", options={"unsigned":true})
     */
    protected $id;

    /** @ORM\Column(length=127,nullable=true) */
    protected $subdomain;


    /** @ORM\Column(length=255,nullable=true) */
    protected $domain;

    /**
     * @ORM\OneToMany(targetEntity="Property", mappedBy="domain", fetch="EAGER", cascade={"persist"})
     */
    protected $properties;

    /**
     * @param \Common\Entity\Property $property
     */
    public function addProperty($property)
    {
        $property->setDomain($this);
        $this->properties[] = $property;
    }

    /**
     * @param string $name
     * @param bool $default
     * @return bool|string
     */
    public function getPropertyValue($name, $default = false) {
        /** @var Property $property */
        foreach ($this->getProperties() as $property) {
            if ($name == $property->getProperty()) {
                return $property->getValue();
            }
        }
        return $default;
    }

    /**
     * @return mixed
     */
    public function getProperties()
    {
        return $this->properties;
    }

    /**
     * @return mixed
     */
    public function getDomain()
    {
        return $this->domain;
    }

    /**
     * @param mixed $domain
     */
    public function setDomain($domain)
    {
        $this->domain = $domain;
    }

    /**
     * @return mixed
     */
    public function getSubdomain()
    {
        return $this->subdomain;
    }

    /**
     * @param mixed $subdomain
     */
    public function setSubdomain($subdomain)
    {
        $this->subdomain = $subdomain;
    }

    public function __construct() {
        $this->properties = new ArrayCollection();
    }
}
<?php
/**
 * Created by PhpStorm.
 * User: Richard
 * Date: 30.11.2014
 * Time: 13:24
 */
namespace Common\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Common\Entity\Property;

/**
 * @ORM\Entity
 * @ORM\Table(name="domain")
 */
class Domain {
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer", options={"unsigned":true})
     */
    protected $id;

    /** @ORM\Column(length=127,nullable=true) */
    protected $subdomain;


    /** @ORM\Column(length=255,nullable=true) */
    protected $domain;

    /**
     * @ORM\OneToMany(targetEntity="Property", mappedBy="domain", fetch="EAGER", cascade={"persist"})
     */
    protected $properties;

    /**
     * @param \Common\Entity\Property $property
     */
    public function addProperty($property)
    {
        $property->setDomain($this);
        $this->properties[] = $property;
    }

    /**
     * @param string $name
     * @param bool $default
     * @return bool|string
     */
    public function getPropertyValue($name, $default = false) {
        /** @var Property $property */
        foreach ($this->getProperties() as $property) {
            if ($name == $property->getProperty()) {
                return $property->getValue();
            }
        }
        return $default;
    }

    /**
     * @return mixed
     */
    public function getProperties()
    {
        return $this->properties;
    }

    /**
     * @return mixed
     */
    public function getDomain()
    {
        return $this->domain;
    }

    /**
     * @param mixed $domain
     */
    public function setDomain($domain)
    {
        $this->domain = $domain;
    }

    /**
     * @return mixed
     */
    public function getSubdomain()
    {
        return $this->subdomain;
    }

    /**
     * @param mixed $subdomain
     */
    public function setSubdomain($subdomain)
    {
        $this->subdomain = $subdomain;
    }

    public function __construct() {
        $this->properties = new ArrayCollection();
    }
}
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="property",options={"collate"="utf8_swedish_ci"})
 */
class Property {
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer", options={"unsigned":true})
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Domain", fetch="EAGER", inversedBy="properties")
     */
    protected $domain;

    /**
     * @ORM\Column(length=45,nullable=true)
     */
    protected $property;

    /**
     * @ORM\Column(type="text",nullable=true)
     */
    protected $value;

    /**
     * @return mixed
     */
    public function getDomain()
    {
        return $this->domain;
    }

    /**
     * @param mixed $domain
     */
    public function setDomain($domain)
    {
        $this->domain = $domain;
    }

    /**
     * @return mixed
     */
    public function getProperty()
    {
        return $this->property;
    }

    /**
     * @param mixed $property
     */
    public function setProperty($property)
    {
        $this->property = $property;
    }

    /**
     * @return mixed
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * @param mixed $value
     */
    public function setValue($value)
    {
        $this->value = $value;
    }



}