Reputation: 3
I'm searching for the solution in a development within a Symfony project with Sonata admin bundle.
2 entities: Contacts and Tags (ManyToMany Relationship)
Within the showaction of the sonata admin (tags entity), I'm unable to order the contacts field. It does not matter if I use the query option within the field or not. I used the query option in the create form, there the query works very well and the items are sorted in the select field.
This works (create form)
protected function configureFormFields(FormMapper $formMapper)
{
$TagsQuery = $this->modelManager
->getEntityManager('TelRegBundle:Tags')
->createQuery(
'SELECT t
FROM TelRegBundle:Tags t
ORDER BY t.title ASC'
);
$formMapper
//...
->add('tags', 'sonata_type_model', array(
'class' => 'TelRegBundle\Entity\Tags',
'property' => 'title',
'multiple' => true,
'query' => $TagsQuery,
))
Where the same approach does not work (show action):
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->with('Tags data')
->add('title')
->end()
->with('Contacts')
->add('contacts', 'entity', array(
'class' => 'TelRegBundle:Contacts',
'associated_property' => 'title',
'query' => ... //Querybuilder not working.
))
->end()
;
}
Anyone who can help? Thx!
Upvotes: 0
Views: 932
Reputation: 245
You can only set annotation
/**
* @ManyToMany(targetEntity="Tags")
* @OrderBy({"title" = "ASC"})
*/
private $tags;
Upvotes: 0