Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Many-To-Many with additional parameters

using the default entity creation commands:

php app/console doctrine:mapping:import testSiteBundle yml
php app/console doctrine:generate:entities test --path=src/

Can i make additional parameters in many-to-many relation table work with symfony2+doctrine2 ?

Example case:

Table Invoice
  - invoice id
Table Product
  - product id
Relation-Table InvoiceProduct
  - invoice id
  - product id
  - product quantity

Doctrine by default don't create relation-tables entities, and trying the example above, the "product quantity" is ignored.

what can i do to manage this?

like image 927
Eduardo Avatar asked Dec 12 '25 06:12

Eduardo


1 Answers

In doctrine, that's not a Many-To-Many relation. It's two OneToMany-Relations with an Entity in the middle

Entity:Invoice - ManyToOne - Entity:InvoiceProduct - OneToMany - Entity:Product

Your additional attributes are just normal fields of the InvoiceProduct-Entity.

like image 182
F.P Avatar answered Dec 14 '25 19:12

F.P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!