I have a form that contains some classics fields and a drop-down list of user objects (processed using AngularJs, and not with the classic form view). When I submit the form, the entire object (and the User selected using the drop-down list) is sent to my controller using an Ajax request.
class MyRestController{
public function MyRestAction(...){
...
$myObject = new MyObject();
$myForm = $this->createForm(new MyFormType(), $myObject);
$myForm->handleRequest($request);
...
}
}
class MyFormType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(...),
->add(...),
->add(...),
->add('user', 'entity', array(
'required' => true,
'class' => 'User',
'property' => 'id',
))
;
...
}
}
Then I save the whole object and clear it. It works great. But the process is insanely slow ...
The problem arises from the handleRequest function when the getChoicesForValue (EntityChoiceList.php) function is called. In my case, the process executes the findAll () query in the user entity, retrieves all the records (thousands) from the database.
, , EntityChoiceList entityLoader:
if ($this->idAsValue && $this->entityLoader) {
} else {
}
( , , EntityChoiceList.php).
, $this->idAsValue true, $this->entityLoader null, , findAll().
, , -, ?
.
:
, handleRequest , , .