Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Closed
Labels
Description
When building a form that has a collection field that contains a form with entity fields using thequery_builder
option, the query is run for each instance in the collection.
Example:
// Main formpublicfunctionbuildForm(FormBuilderInterface$builder,array$options){$builder ->add('participants','collection',array('type' =>newParticipantType(),'allow_add' =>true,'allow_delete' =>true,'by_reference' =>false, ));}// Form used in collection (ParticipantType)publicfunctionbuildForm(FormBuilderInterface$builder,array$options){$builder ->add('user','entity',array('class' =>'MyUserBundle:User','query_builder' =>function(EntityRepository$er) {return$er->createQueryBuilder('u') ->orderBy('u.surname','ASC'); }, )) ->add('relationship','entity',array('class' =>'MyOtherBundle:Relationship','query_builder' =>function(EntityRepository$er) {return$er->createQueryBuilder('r') ->orderBy('r.name','ASC'); }, ));}
Now, if I generate this form with an entity that has 30participants
, the query builder is run for both theuser
andrelationship
entity fields 30 times, resulting in 60 queries. Surely each query only needs to be run once?