How to create entities with composite key in Doctrine?

Asked

Viewed 598 times

0

I have a database that works with composite keys, and I am implementing the use of laravel framework.

This is my bank’s structure: Relacionamento do banco I’m using the Doctrine as ORM and discovered that I can not automatically generate the entities of the bank, since the tables have composite keys. I’m using the remote php artisan doctrine:convert:mapping annotation ./entidades --from-database --force. The return to this command is :

[Doctrine\ORM\Mapping\MappingException]
It is not possible to map entity 'FinContaspagar' with a composite primary key as part of the primary key of another entity 'FinContaspagarDetalhe#grupo'.

This way, I am creating the entities manually, however I followed the tutorial of Doctrine in relation to the creation of @ManyToOne @OneToMany but I still haven’t been able to create the relationship the right way. Does anyone know a way or tool to generate these entities or has some example like this of several composite keys?

1 answer

2


Using version 2+ of Doctrine one way to manually map your entities is by placing @Id on your attributes that are part of your primary key, in which case there is a restriction on using @Generatedvalue, you cannot use it.
Here the example of the framework doc itself: Composite primary key

Browser other questions tagged

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