1

関連するエンティティがあり、そのすべての関係でエンティティをシリアル化したいのですが、シリアル化は正常に機能します (私は思います)。たとえば、この json を保存します。

{  
  "relation_one":1,
  "relation_two":1,
  "relation_three":1,
  "other_integer_data":2996,
  "other_integer_data2":1174
}

後者でデシリアライズしようとすると、取得するのは

{  
  "other_integer_data":2996,
  "other_integer_data2":1174
}

関連を示すプロパティはマッピングされません。逆シリアル化後に適切にマップされたオブジェクトを取得するために必要なこと。

私のエンティティコード:

/**
 * @var RelationOne
 *
 * @ORM\ManyToOne(targetEntity="RelationOne", inversedBy="entity")
 * @ORM\JoinColumn(name="relation_one_id", referencedColumnName="id", nullable=true, onDelete="RESTRICT")
 * @Assert\NotBlank()
 * @Assert\Valid()
 */
private $relationOne;

/**
 * @var RelationTwo
 *
 * @ORM\ManyToOne(targetEntity="RelationTwo", inversedBy="entity")
 * @ORM\JoinColumn(name="relation_two_id", referencedColumnName="id", nullable=true, onDelete="RESTRICT")
 * @Assert\NotBlank()
 * @Assert\Valid()
 */
private $relationTwo;

/**
 * @var RelationThree
 *
 * @ORM\ManyToOne(targetEntity="RelationThree", inversedBy="entity")
 * @ORM\JoinColumn(name="relation_three_id", referencedColumnName="id", nullable=true, onDelete="RESTRICT")
 * @Assert\NotBlank()
 * @Assert\Valid()
 */
private $relationThree;



/**
 * @JMS\VirtualProperty
 * @JMS\SerializedName("relation_one")
 * @return integer
 */
public function getVirtualRelationOne()
{
    if ($this->relationOne) {
        return $this->relationOne->getId();
    }

    return null;
}

/**
 * @JMS\VirtualProperty
 * @JMS\SerializedName("relation_two")
 * @return integer
 */
public function getVirtualRelationTwo()
{
    if ($this->relationOne) {
        return $this->relationOne->getId();
    }

    return null;
}

/**
 * @JMS\VirtualProperty
 * @JMS\SerializedName("relation_three")
 * @return integer
 */
public function getVirtualRelationThree()
{
    if ($this->relationThree) {
        return $this->relationThree->getId();
    }

    return null;
}

編集 いくつかのテストの後、これらのリレーションIDは仮想メソッドのためにのみ設定され、それらがないとイベントがシリアル化されないことがわかったので、変更された質問は、リレーションを持つエンティティを適切にシリアル化および逆シリアル化する方法です.

4

0 に答える 0