In my entities, I have a many to many relationship between roles and users
/**
* @ORM\ManyToMany(targetEntity="User", mappedBy="roles")
*/
protected $users;
In the edit form for the Role
entity I'd like to be able to see the users with that role, and to add and remove users too, so I added a users
field in configureFormFields
protected function configureFormFields(FormMapper $formMapper) {
$formMapper
->add('name')
->add('description')
->add('users');
}
The problem is that Sonata's approach is very naive: to render this form, it executes one query to retrieve the fields of the role, one to retrieve the fields of the users with this role, and one to retrieve the fields of ALL THE USERS IN THE DATABASE!!!
As I have more than 20,000 users in the database, this uses more than 250MB of memory.
Is there a way to instruct Sonata to show a paginated list with search or something like that?