doctrine2 - Symfony - Discard association field during hydration process of an EntityType querybuilder -
my symfony (3.3) form entitytype displayed select input , lists clients have in database. client entity associated several other entities using lazy mode.
when select box rendered, 204 db queries issued. suspect form component call setters against each query result, resulting in loading of many additional database queries.
we set association mapping "eager" guess, or use join('…')->addselect('…') methods inside form's querybuilder option force datas part of results, hydration process still costly when several entities involved.
can see, tried use doctrine query hint, hoping solve problem did not change anything.
then, way go such use case ?
should in order fields need populate dropdown input ?
here tried far:
$builder->add('parent', entitytype::class, [ 'class' => client::class, ,'required' => false ,'multiple' => false ,'query_builder' => function (entityrepository $er) { $qb = $er ->createquerybuilder('c') // want doctrine fetch following fields ->select('partial c.{id,uuid,name,shortname}'); // expected flag not change total amount of queries executed $qb->getquery()->sethint(query::hint_force_partial_load, true); return $qb; } ])…
thank you.
solved
one of association onetoone , 1 has mapping "fetch" key set 'eager'.
expected doctrine automatically join , select such association when using default entitytype's querybuilder, not , had explicitly tell querybuilder (once again, despite fetch flag set 'eager').
return $qb->select('c, p')->leftjoin('c.param', 'p');
i don't point here on what's going on underneath, still number of database requests dropped down 4 queries.
Comments
Post a Comment