我正在尝试保存反序列化的 OneToMany 连接,但学说将父项 ($parent) 的 id 字段留空。
class MyParent
{
/**
* @ORM\OneToMany(targetEntity="MyChild", mappedBy="parent", cascade={"persist"})
*
* @Serializer\Expose
* @Serializer\SerializedName("Children")
* @Serializer\Type("ArrayCollection<MyNamespace\MyChild>")
* @Serializer\XmlList(entry="Children")
*
* @var \Doctrine\Common\Collections\ArrayCollection
*/
private $children;
}
class MyChild
{
/**
* @var MyParent
*
* @ORM\ManyToOne(targetEntity="MyParent", inversedBy="children")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
* })
*/
private $parent;
}
我正在尝试使用 JMS 序列化程序:
$entity = $serializer->deserialize($myXmlAsString, 'MyNamespace\MyParent', 'xml');
$entityManager->persist($entity);
$entityManager->flush($entity);
结果:所有数据都保存到数据库中,但孩子的列 parent_id 为空!
xml 不包含任何 ID。无论如何,ID 都被排除在(反)序列化之外,因为我想忽略它们。
我的配置有什么问题?