sonata-project/SonataAdminBundle — Issue #586: error: Datagrid Filters based on ManyToMany relations
Author: butt
Created: 2012-02-29 08:14:43+00:00
State: open

After digging a while into problem I have located reasons - I got error when I try to use Datagrid Filters based on ManyToMany relations.

For example - I have entity article

/**
* Vendors for article
*
* @ORM\ManyToMany(targetEntity="Vido\CoreBundle\Entity\Vendor")
* @ORM\JoinTable(name="articles_vendors",
* joinColumns={@ORM\JoinColumn(name="article_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="vendor_id", referencedColumnName="id")}
* )
*/
public $vendors;

When I use code

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('vendors')
;
}

I got error

Iterate with fetch join in class Vido\CoreBundle\Entity\Article using association vendors not allowed.

when I comment that line like

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
// ->add('vendors')
;
}

Batch action works fine.