I'm trying to save a deserialized OneToMany connection, but doctrine leaves the id-field of the parent item ($parent) empty.
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;
}
I'm trying this by using the JMS Serializer:
$entity = $serializer->deserialize($myXmlAsString, 'MyNamespace\MyParent', 'xml');
$entityManager->persist($entity);
$entityManager->flush($entity);
The result: All data is saved into database but the column parent_id of children is null!
The xml does not contain any ids. The ids are excluded from (de)serialization anyway, because I want to ignore them.
What is wrong in my configuration?