sonata-project / SonataDoctrineORMAdminBundle

Integrate Doctrine ORM into the SonataAdminBundle
https://docs.sonata-project.org/projects/SonataDoctrineORMAdminBundle
MIT License
445 stars 345 forks source link

3.2.0 composite key gives Invalid PathExpression, worked with 3.1.7 #766

Closed yurtesen closed 6 years ago

yurtesen commented 6 years ago

Environment

Sonata packages

$ ./composer.phar show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.28.0 3.28.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.8.0  3.8.0  Symfony SonataBlockBundle
sonata-project/cache                     1.0.7  1.0.7  Cache library
sonata-project/core-bundle               3.7.1  3.7.1  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.3.0  2.3.0  Symfony SonataDatagridBundle
sonata-project/doctrine-orm-admin-bundle 3.2.0  3.2.0  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.8.0  1.8.0  Lightweight Exporter library

Symfony packages

$ ./composer.phar show --latest 'symfony/*'
symfony/monolog-bundle     v3.1.2 v3.1.2 Symfony MonologBundle
symfony/phpunit-bridge     v4.0.0 v4.0.0 Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.6.0 v1.6.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu  v1.6.0 v1.6.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.6.0 v1.6.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56     v1.6.0 v1.6.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.6.0 v1.6.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util      v1.6.0 v1.6.0 Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.0 v3.0.0 Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v3.1.6 v3.1.6 Symfony SwiftmailerBundle
symfony/symfony            v3.4.0 v3.4.0 The Symfony PHP framework

PHP version

$ php -v
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

Subject

I have a simple table with composite key which is consisting of relations to 2 other tables

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Store", inversedBy="stores")
     * @ORM\JoinColumn(nullable=false,onDelete="CASCADE")
     * @ORM\Id()
     * @ORM\GeneratedValue("NONE")
     * @var $store \AppBundle\Entity\Store
     */
    protected $store;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Product", inversedBy="products")
     * @ORM\JoinColumn(referencedColumnName="gtin",nullable=false,onDelete="CASCADE")
     * @ORM\Id()
     * @ORM\GeneratedValue("NONE")
     * @var $product \AppBundle\Entity\Product
     */
    protected $product;

Admin class is simple:

class StoreProductAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('store', 'entity', array(
                'class' => 'AppBundle\Entity\Store'
            ))
            ->add('product', 'entity', array(
                'class' => 'AppBundle\Entity\Product'
            ));
    }
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('store')
            ->add('product');
    }
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('store')
            ->addIdentifier('product');
    }
}

In services.yml the definition is as:

    sonata_admin.store_product:
        class: AppBundle\SonataAdmin\StoreProductAdmin
        arguments: [~, AppBundle\Entity\Store\Product, ~]
        tags:
            - { name: sonata.admin, manager_type: orm, label: Store Product }
        public: true

Everything was great with v3.1.7 release but with v3.2.0 I am getting an error message about Invalid PathExpression when I go to table listing in SonataAdminBundle

Steps to reproduce

Create a table with composite keys with ManyToOne relation. If I add a separate ID column, things work normally.

Expected results

List of elements would be shown

Actual results

Doctrine\ORM\Query\ QueryException
[Semantical Error] line 0, col 78 near 'store, o.product': Error: Invalid PathExpression. Must be a StateFieldPathExpression.

Doctrine\ORM\Query\ QueryException
SELECT DISTINCT IDENTITY(o.store) as store, IDENTITY(o.product) as product, o.store, o.product FROM AppBundle\Entity\Store\Product o LEFT JOIN o.store s_store LEFT JOIN o.product s_product ORDER BY o.store ASC, o.product ASC
greg0ire commented 6 years ago

Can you please use git bisect to find the offending commit?

dmarkowicz commented 6 years ago

It is because #728. ProxyQuery::addOrderedColumns should skip columns that have already been added to the SELECT as IDENTITY(column). I will try to provide a patch this weekend.

yurtesen commented 6 years ago

Thanks for the quick response :)

e9e3a5c8135177e7946d2872bc6bcbf5d77dff7f is the first bad commit
commit e9e3a5c8135177e7946d2872bc6bcbf5d77dff7f
Author: Dariusz Markowicz <dmarkowicz77@gmail.com>
Date:   Mon Sep 25 07:54:07 2017 +0200

    Fix sorting by multiple columns in PostgreSQL and MySQL 5.7 (#728)

    Adapt the getFixedQueryBuilder function to be compatible with PostgreSQL and MySQL 5.7 with ONLY_FULL_GROUP_BY mode. For any orderBy clause defined directly in the dqlParts, we add a select entry in the query.

:040000 040000 7813e3f71d57df5b8eeca760fc18a065bc2ff131 a59ded98674ff8dfc7cd49bc336e46d1f7bd07d3 M  Datagrid
:040000 040000 d0d01e00dabd54d2a087f1270425d94848dc4b22 c1cabfaa5f349469e32a0c639f13a51a85d05686 M  Tests
:100644 100644 9ded7cfcf53271a9d6c1ac74ad81963490738b04 6bfc72eab2325bfa08dfd1b0c8bb6d35d4469c6a M  composer.json