Symfony2嵌入表单和左连接实体

Symfony2嵌入表单和左连接实体,symfony,doctrine,Symfony,Doctrine,我有两个实体,使用左连接可以正常工作。 当我尝试使用表单和描述进行编辑时,出现的问题是null(找不到行)。如何确保Description.productid填充了Product.productid object(Test\AdminBundle\Entity\Product)#245 (5) { ["productid":protected]=> string(4) "8989" ["product":protected]=> string(12) "Test Te

我有两个实体,使用左连接可以正常工作。 当我尝试使用表单和描述进行编辑时,出现的问题是null(找不到行)。如何确保Description.productid填充了Product.productid

object(Test\AdminBundle\Entity\Product)#245 (5) {
  ["productid":protected]=>
  string(4) "8989"
  ["product":protected]=>
  string(12) "Test Test"
  ["price":protected]=>
  string(4) "9,95"
  ["groupid":protected]=>
  string(2) "72"
  ["description":protected]=>
 object(Test\AdminBundle\Entity\Description)#417 (3) {
    ["productid":protected]=>
    NULL
    ["description":protected]=>
    string(4) "qweq fdasd"
  }
}

class Product
{
    /**
     * @Assert\NotBlank(groups={"edit"})
     * @Assert\Range(min = "100", max = "99999", groups={"search", "edit"})
     * @ORM\Id
     * @ORM\Column(type="integer")
     */
    protected $productid;

    ...

    /**
     * @Assert\Type(type="Test\AdminBundle\Entity\Description")
     * @ORM\OneToOne(targetEntity="Description", cascade={"persist"})
     * @ORM\JoinColumn(name="productid", referencedColumnName="productid")
     */
    protected $description; 

    ...
}


class Description
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     */
    protected $productid;

    /**
     * @ORM\Column(type="text")
     */
    protected $description;

    ...
}
我的表(mysql myisam)都使用与主键相同的productid:

product
productid | price | morecolumns | ...

description
productid | description | morecolumns | ...

您只需在
Product
实体的
addDescription(description$description)
方法中添加
$description->setProduct($this)
。因此,无论何时向产品添加新的描述对象,它都会自动填充该字段。

我通过添加
$this->description->setProductid($this->getProductid())以设置描述。这是首选的解决方案吗?我认为我的实体类需要编辑才能处理这个问题。最好设置整个对象,而不仅仅是它的ID。所以只需调用
$this->description->setProduct($this)而不是
$this->description->setProductid($this->getProductid())和条令将自动识别其ID。这是首选解决方案。我明白了,但我的
描述
实体没有
setProduct
方法,因为它是单向关系。