我有两个使用教条左连接正常工作的实体。 当我尝试使用表单进行编辑并且Description为null(未找到行)时,会出现问题。如何确保使用Product.productid填充Description.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 | ...
答案 0 :(得分:0)
您只需在$description->setProduct($this)
实体的addDescription(Description $description)
方法中添加Product
即可。因此,每当您向产品添加新的描述对象时,它都会自动填充该字段。