php - MySQL Doctrine YAML -


what want product , product should this:

{   idproduct: 1,   maincategory: 1, // 1 of categories main one.   categories: [1, 2, 3],   name: "john" //and on.. important thing maincategory... } 

im using doctrine (at work) yaml, , know use this:

product:   type: entity   manytomany:     groups:       targetentity: category       jointable:         name: products_categories         joincolumns:           product_id:             referencedcolumnname: id         inversejoincolumns:           category_id:             referencedcolumnname: id 

that create 3 tables (use imagination xd):

**product** id  **category** id  **category_product** id_product id_category 

but need maincategory in product too:

**product** id main_category #this important , problem. 

what can achieve this... put object example in json because easy understand... im using php @ work, doctrine.. guess doctrine2, im not sure that.

at work have in production category , product working in 1 one relationship... today 1 product can have 1 category, issue change that, because 1 product can have several categories 1 main one.

thanks in advance!!!

edit: @ work suggest me, third entitie, im not sure that.

maybe can think outside of box little , define maincategory id. id can used categories. instead of calling maincategory via regular doctrine, write custom function maincategory object maincategory id.

yes, manual work, doctrine not natively support scenario. important thing worry making sure maincategory , categories stay in sync such can never have maincategory not in category. can though if check maincategory in categories on save.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -