6

I have "customers", "products" and "versions" tables.Each customer, can have more than one product, and each product has more than one version. I have created many-to-many relation "customers_products" and everything works perfect.

Also I have created one-to-many relation between "products" and "versions".

QUESTION: How to add an extra column (version_id) in "customers_products" table so I can build form where user can choose products and version to create new customer.

user3722402
  • 101
  • 1
  • 1
  • 8

2 Answers2

9

Once an association has data, it's no more an association.

You have to implement two ManyToOne instead of a ManyToMany.

See this great answer on this question for a full example.

You can get a lot of other examples by googling the title of your question.

Community
  • 1
  • 1
chalasr
  • 12,971
  • 4
  • 40
  • 82
0

Adding an extra column to the association of a many-to-many it actually changes the meaning of that relationship. In order to represent that with Doctrine, you'd need to change the association to be a one-to-many/many-to-one between the three entities.

You'll end up with three entities in your domain model, which would allow you to access to the version of a CustomerProduct entity.

You can read a bit more detailed explanation in Doctrine's docs.

hasumedic
  • 2,139
  • 12
  • 17