Search code examples
phpsymfonydoctrine-ormjmsserializerbundlejms-serializer

Jms serializer @JMS\Inline() annotation overrides an actual id


I have product and product_detail tables in database.

enter image description here

Every product has a product detail.

class Product
{
   /**
     * @var ProductDetail
     * @JMS\ReadOnly()
     * @ORM\OneToOne(targetEntity="ApiBundle\Entity\ProductDetail", mappedBy="product", cascade={"persist"})
     * @JMS\Inline()
     */
    private $detail;
}

I use @JMS\Inline() annotation to show only detail information of product_detail table. But when I serialize a product I get wrong id. It must be product id but id returns an product detail id. Is it bug or I am doing something wrong?


Solution

  • You should not expose the id from the detail when using inline.

    Source: https://github.com/schmittjoh/JMSSerializerBundle/issues/460#issuecomment-113440743