APY / APYDataGridBundle

Symfony Datagrid Bundle
MIT License
493 stars 343 forks source link

Issue with filter with manytomany? #526

Closed clubdesarrolladores closed 8 years ago

clubdesarrolladores commented 10 years ago

Hi.

This code was working, but now show a error in the generated DQL. This is the important code:

The entity

/**
 * @Grid\Source(columns="id, customer.name, tags.name:GroupConcat:distinct, name, invoicingStatus, date_start, date_finish")
 */
class Project extends Service
{

    /**
     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="projects")
     * @ORM\JoinTable(name="webfactory_service_projects_tags")
     * @Assert\NotBlank()
     * @Grid\Column(field="tags.name:GroupConcat:distinct", title="Tags")
     */
    protected $tags;

The controller:

        $source->manipulateQuery(function (\Doctrine\ORM\QueryBuilder $qb) use ($tableAlias) {
                    $emConfig = $qb->getEntityManager()->getConfiguration();
                    $emConfig->addCustomDatetimeFunction('GroupConcat', 'DoctrineExtensions\Query\Mysql\GroupConcat');
                    $qb->groupBy($qb->getRootAlias() . '.id');
                });

And this is the error message:

[2/2] QueryException: [Semantical Error] line 0, col 175 near 'tags::name:GroupConcat:distinct': Error: 'tags::name:GroupConcat:distinct' is not defined. 

[1/2] QueryException: SELECT DISTINCT _customer.name as customer::name FROM WebFactory\ServiceBundle\Entity\Project _a LEFT JOIN _a.customer _customer LEFT JOIN _a.tags _tags GROUP BY _a.id HAVING tags::name:GroupConcat:distinct = ?123 ORDER BY _customer.name asc

This happens only when de user filter by tags

Abhoryo commented 10 years ago

Where do you have this query ? In the execute method or in the getTotalCount method ?

Can you show me the configuration of the customer.name field because I can't understand where the DISTINCT _customer.name statement came from.

clubdesarrolladores commented 10 years ago

This definition is in Service, not in Project class.

/**
     * @var Customer $customer
     *
     * @ORM\ManyToOne(targetEntity="\WebFactory\CompanyBundle\Entity\Customer", inversedBy="services", cascade={"persist"})
     * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", nullable=true)
     * @Assert\NotBlank
     * @Grid\Column(title="Customer", field="customer.name", filter="select", selectFrom="query", operatorsVisible=false)
     * @Grid\Column(field="customer.id", filterable=false, visible=false)
     */
    protected $customer;

I'm not sure, but i guest is in getTotalCount.

Abhoryo commented 10 years ago

You shouldn't have a dinstinct here.

clubdesarrolladores commented 10 years ago

I know. I can not be precise in time but initially it worked fine. It was an update which broke the feature.