Symfony2 : How to merge form in three entity one-to-one relation scenario -
scenario:
customer table: id(pk),customer_name,address
customer_detail table: id(pk),customer_id(fk),phone,email
credit table: id(pk),customer_id(fk), credit_code, description
there unidirectional one-to-one relation in client detail , credit client table.
i have created entity class , form type both. able insert separate form.
i want show form , value entered should inserted respective tables.
customer name:___________________
address: ________________________
phone: __________________________
email: __________________________
credit code: ____________________
credit description: _____________
i find out have write $builder->add('customer',new customertype()); code in client detail form , trying @ client form. but, in case of 3 entity how can merge form ?
the credit table has no relation client detail table ?
table diagram:
http://i.stack.imgur.com/nxioq.png
i don't see problem here, 1. create customertype form:
... $builder->add('customer_name')->add('address', 'textarea'); ... 'data_class' => 'vendor\bundle\entity\customer'
2. create customerdetailtype:
... $builder->add('customer', new customertype())->add('phone')->add('email', 'email'); ... 'data_class' => 'vendor\bundle\entity\customerdetail'
3. create myformtype:
... $builder->add('customer_details', new customerdetailtype()/* field requires 'mapped' => false alternative , handled manually */)->add('credit_code')->add('description', 'textarea'); ... 'data_class' => 'vendor\bundle\entity\credit'
also should @ doctrine's cascade
options..
ps// in such situations this: client has relationship customerdetails, customerdetails has relationship credit:
customer: - field: customerdetails customerdetails: - field: credit
after embedded form this:
credit:
... $builder->add('credit_code')->add('description', 'textarea'); ... 'data_class' => 'vendor\bundle\entity\credit'
customerdetails:
... $builder->add('phone')->add('email', 'email')->add('credit', new credittype()); ... 'data_class' => 'vendor\bundle\entity\customerdetail'
customertype:
... $builder->add('customer_name')->add('address', 'textarea')->add('customerdetail', new customerdetailtype()); ... 'data_class' => 'vendor\bundle\entity\customer'
with cascade persist
alternative formcomponent , doctrine automatically save entities..
forms symfony2
No comments:
Post a Comment