symfony - build form for tables with many relations -
i have got problem build forms many relations between tables. structure of relations can see on below picture:
my relations in yml:
######### products.orm.yml ######### type: entity table: products fields: ... lifecyclecallbacks: { } onetomany: productcombinations: targetentity: productscombinations mappedby: product ######### productscombinations.orm.yml ######### type: entity table: products_combinations fields: ... lifecyclecallbacks: { } onetomany: productattributes: targetentity: productsattributesjoin mappedby: productcombinations manytoone: product: targetentity: products inversedby: productcombinations joincolumn: name: product_id referencedcolumnname: id ######### productsattributesjoin.orm.yml ######## type: entity table: null fields: combinationid: type: bigint column: combination_id id: true generator: strategy: none attributeid: type: bigint id: true generator: strategy: none column: attribute_id lifecyclecallbacks: { } manytoone: productcombinations: targetentity: productscombinations inversedby: productattributes joincolumn: name: combination_id referencedcolumnname: combination_id attributes: targetentity: attributes inversedby: productattributesjoin joincolumn: name: attribute_id referencedcolumnname: id ######### attributes.orm.yml ######### type: entity table: products_attributes fields: ... lifecyclecallbacks: { } onetomany: productattributesjoin: targetentity: productsattributesjoin mappedby: attributes manytoone: productattributesdefinitions: targetentity: attributesdefinitions inversedby: productattributes joincolumn: name: attribute_id referencedcolumnname: id ######### attributesdefinitions.orm.yml ######### type: entity table: products_attributes_definitions fields: ... lifecyclecallbacks: { } onetomany: productattributes: targetentity: attributes mappedby: productattributesdefinitions manytoone: productattributesdefinitions: targetentity: attributesdefinitions inversedby: productattributes joincolumn: name: attribute_id referencedcolumnname: id
what have got know that:
what not working when click add new got popup fields productscombinations when fill them in , press save showing error product_id null (but should take products).
also that:
also bit of code admin directory:
###### productsview.php ###### $formmapper->with('attributes') ->add('productcombinations', 'sonata_type_collection') ->end() ###### productscombinations.php ###### $formmapper ->with('general') ->(some main fields productcombinations) ->add('productattributes', 'sonata_type_collection', array(), array( 'edit' => 'inline', 'inline' => 'table', 'sortable' => 'position' )) ###### productsattributesjoin.php ###### $formmapper ->with('general') ->add('attributes', 'sonata_type_model') ->end() ;
for first part, in product
entity, have addproductcombinations
method. make so:
public function addproductcombinations($object) { $this->productcombinations[] = $object; $object->setproduct($this); // line important. }
this should moving. alternatively, can set product inside prepersist
/ preupdate
actions in admin.
the second part of question bit unclear. want have attributes of different types text / choice / multiple choice? if so, have dynamically modify form using how dynamically modify forms using form events. hey, maybe can reuse existing bundles, packagist: assortment.
Comments
Post a Comment