What I want is get the product and the product should be something like this:
{
idProduct: 1,
mainCategory: 1, // One of the categories is the main one.
categories: [1, 2, 3],
name: "John" //and so on.. the important thing is mainCategory...
}
Im using Doctrine (at work) with YAML, and I know I could use something like this:
Product:
type: entity
manyToMany:
groups:
targetEntity: Category
joinTable:
name: products_categories
joinColumns:
product_id:
referencedColumnName: id
inverseJoinColumns:
category_id:
referencedColumnName: id
That would create something like this three tables (use your imagination xD):
**Product**
id
**Category**
id
**Category_Product**
id_product
id_category
But I need mainCategory in the product too:
**Product**
id
main_category #this is important and my problem.
What can I do to achieve this... I put an object example in json because is easy to understand... but Im using PHP at work, with Doctrine.. I guess Doctrine2, Im not sure about that.
At work I have in production category and product already working but in a one to one relationship... today one product can have only one category, my issue is change that, because one product can have several categories but one is the main one.
Thanks in advance!!!
Edit: Someone at work suggest me, a third entitie, but Im not sure about that.