Symfony Single id is not allowed on Composite Primary key in Entity

Asked

Viewed 436 times

2

I have a view, where Mapeei 3 fields as primary key and 2 of these fields are foreign keys

As below:

/**
     * @var NotaFiscal
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="NotaFiscal", inversedBy="itens")
     * @ORM\JoinColumn(name="CODIGO", referencedColumnName="CODIGO")
     */
    private $notaFiscal;

    /**
     * @var Produto
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="Produto")
     * @ORM\JoinColumn(name="CD_PRODUTO", referencedColumnName="CD_PRODUTO")
     */
    private $produto;

    /**
     * @var string
     * @ORM\Id
     * @ORM\Column(name="CD_LOTE")
     */
    private $lote;

I can’t see where the mistake is... Single id is not allowed on Composite Primary key in Entity

1 answer

1

Let @ORM\Id only on the primary key.

For more reference on Doctrine field mapping and annotations, see Basic Mapping

  • The 3 fields is a composite key.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.