次のような JSON オブジェクトがあります。
{
"childEntity" : {
"bar": "foo"
},
"someproperty" : "2.0"
}
JMS シリアライザー バンドルを使用して、このオブジェクトをデシリアライズし、Doctrine2 オブジェクトに変換します。
$myObject = $serializer->deserialize($jsonStringJustAbove, "My\FooBundle\Entity\masterEntity", 'json');
$myObject = $em->merge($myObject);
$myObject->persist($tour);
$myObject->flush();
これが私の「masterEntity」クラスです:
class masterEntity {
/**
* @JMS\Type("ArrayCollection<My\FooBundle\Entity\childEntity>")
* @ORM\OneToMany(targetEntity="childEntity", mappedBy="masterEntity", cascade={"remove", "persist", "merge"})
*/
private $childentities;
public function setChildEntities(ArrayCollection $childentities)
{
$this->childentities = $childentities;
}
}
これが私の「childEntity」クラスです:
class childEntity {
/**
* @JMS\Type("My\FooBundle\Entity\masterEntity")
* @ORM\ManyToOne(targetEntity="My\FooBundle\Entity\masterEntity", inversedBy="childEntities", cascade={"persist"})
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @ORM\Id
*/
private $masterEntity;
/**
* @JMS\Type("My\FooBundle\Entity\barEntity")
* @ORM\ManyToOne(targetEntity="My\FooBundle\Entity\barEntity")
* @ORM\JoinColumn(nullable=false)
* @ORM\Id
*/
private $barEntity;
public function setMasterEntity(masterEntity $masterEntity)
{
$this->masterEntity = $masterEntity;
}
public function setBarEntity(barEntity $barEntity)
{
$this->barEntity = $barEntity;
}
}
受け取った JSON オブジェクトは、すべての childEntities として、データベースにまだ存在しません。
デシリアライザーが masterEntity とそのすべての子をデータベースに保存する準備をすることを期待しています。私の最初の質問は次のとおりです。シリアライザーを実行すると、マージ関数は次のように機能します。
$masterEntity = new masterEntity();
$childEntity = new childEntity();
$childEntity->setMasterEntity($masterEntity);
$childEntity->setBarEntity($foo);
masterEntity (2 番目のコード ブロック) を保存しようとすると、次のエラーが表示されるため、よくわかりません。
Notice: Undefined index: 0000000069332c43000000007c145082 in ../vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2740
注 : Doctrine 2.3.2 および JMS Serializer dev-master で Symfony 2.1.8 を使用しています (2013 年 3 月 4 日現在)。
私がやろうとしていることが正しく、論理的で、可能かどうか教えてもらえますか? はいの場合、なぜこのエラーが発生するのですか? それを取り除く方法は?
ありがとうございます。