php - Symfony3.0.3 ChoiceType choose among entity entries via checkboxes and save the chosen to simple_array MySQL -


here situation:

  1. i have entity jobtypes contains name , description fields
  2. i making registration form , user registering supposed able choose among jobtypes entries name. far good
  3. i want list available options (jobtypes entries) checkboxes, user can choose 1 or more save checked ones simple_array type in mysql.
  4. i building form using symfony 3.0.3

the problem:

everything looks good, until check database. chosen jobtypes not displayed names weird kind of path?

example:

i want 'name1','name2',.....

i get doctrine\common\collections\arraycollection@0000000010bec20a0000000010aaccb8

the question

how should build ->add() field in symfony in order done?

this have far

->add('interestedin', collectiontype::class, array(             'entry_type'=>choicetype::class, array(                 'expanded'=>true,'multiple'=>true,'choices'=>array(                    'class'=>'appbundle\entity\jobtypes','choice_label'=>'name')))) 

this how data

$interestedin = array(); $interestedin[] = $form['interestedin']->getdata(); 

and how set object

$sprovider->setinterestedin($interestedin); 

sprovider.php

/**  * @var array  *  * @orm\column(name="interestedin", type="simple_array")  */ private $interestedin; 

i can't think of else show might answer question. if there missed, please tell.

edit

when {{ dump(sprovider.interestedin) }}

i

array(1) { [0]=> object(doctrine\common\collections\arraycollection)#489 (1) { ["elements":"doctrine\common\collections\arraycollection":private]=> array(2) { [0]=> object(appbundle\entity\jobtypes)#482 (3) { ["id":"appbundle\entity\jobtypes":private]=> int(1) ["name":"appbundle\entity\jobtypes":private]=> string(15) "kitchen fitting" ["description":"appbundle\entity\jobtypes":private]=> string(32) "building kitchen scratch." } [1]=> object(appbundle\entity\jobtypes)#487 (3) { ["id":"appbundle\entity\jobtypes":private]=> int(2) ["name":"appbundle\entity\jobtypes":private]=> string(16) "bathroom fitting" ["description":"appbundle\entity\jobtypes":private]=> string(24) "rennovate bathroom." } } } }

i think i'm not getting names of jobs in $interestedin, whole entries. hope helps bit.

why want store them array? looks manytomany relation.

for simple_array type, doctrine store in db field , imploded , serialized representation of objects array. you'll lose basic filtering options on mysql side.


Comments