Closed multifinger closed 6 years ago
Will be fixed by #768.
I'm running into the same issue, even with 3.3 of this bundle.
My Entity:
/**
* @Gedmo\Tree(type="nested")
* @ORM\Entity(repositoryClass="MenuRepository")
* @ORM\Table()
* @ORM\ChangeTrackingPolicy(value="DEFERRED_EXPLICIT")
*/
class Menu
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
*/
private $title;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $subtitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $url;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": false})
*/
private $active = false;
/**
* @Gedmo\TreeLeft
* @ORM\Column(name="lft", type="integer")
*/
private $lft;
/**
* @Gedmo\TreeLevel
* @ORM\Column(name="lvl", type="integer")
*/
private $lvl;
/**
* @Gedmo\TreeRight
* @ORM\Column(name="rgt", type="integer")
*/
private $rgt;
/**
* @Gedmo\TreeRoot
* @ORM\ManyToOne(targetEntity="MenuBundle\Entity\Menu")
* @ORM\JoinColumn(name="tree_root", referencedColumnName="id", onDelete="CASCADE")
*/
private $root;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="MenuBundle\Entity\Menu", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="MenuBundle\Entity\Menu", mappedBy="parent")
* @ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
}
In my admin:
/**
* {@inheritdoc}
*/
public function createQuery($context = 'list')
{
$em = $this->modelManager->getEntityManager($this->getClass());
/** @var $cmd \Doctrine\Common\Persistence\Mapping\ClassMetadata */
$classMetaData = $em->getMetadataFactory()->getMetadataFor($this->getClass());
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $em
->createQueryBuilder('m')
->select('m')
->from($this->getClass(), 'm');
$queryBuilder->orderBy('m.root, m.lft');
return new ProxyQuery($queryBuilder);
}
Results in:
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 24 near 'root, m.lft,': Error: Invalid PathExpression. Must be a StateFieldPathExpression.").
Php version:
PHP 7.1.11 (cli) (built: Oct 28 2017 17:36:49) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.11, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
with blackfire v1.18.0~linux-musl-x64-non_zts71, https://blackfire.io, by SensioLabs
Sonata packages:
sonata-project/admin-bundle 3.28.0
sonata-project/block-bundle 3.9.0
sonata-project/cache 2.0.1
sonata-project/core-bundle 3.7.1
sonata-project/datagrid-bundle 2.3.1
sonata-project/doctrine-orm-admin-bundle 3.3.0
sonata-project/exporter 1.8.0
Symfony:
symfony/monolog-bundle v3.1.2
symfony/phpunit-bridge v3.4.1
symfony/polyfill-apcu v1.6.0
symfony/polyfill-intl-icu v1.6.0
symfony/polyfill-mbstring v1.6.0
symfony/polyfill-php56 v1.6.0
symfony/polyfill-php70 v1.6.0
symfony/polyfill-util v1.6.0
symfony/security-acl v3.0.0
symfony/swiftmailer-bundle v3.1.6
symfony/symfony v3.4.1
Doctrine:
doctrine/annotations v1.6.0
doctrine/cache v1.7.1
doctrine/collections v1.5.0
doctrine/common v2.8.1
doctrine/data-fixtures v1.3.0
doctrine/dbal v2.6.3
doctrine/doctrine-bundle 1.8.1
doctrine/doctrine-cache-bundle 1.3.2
doctrine/doctrine-fixtures-bundle v2.4.1
doctrine/inflector v1.2.0
doctrine/instantiator 1.1.0
doctrine/lexer v1.0.1
doctrine/orm v2.5.13
Any help would be greatly appreciated
Not sure if this is the same issue, was it working before with some version and not after an upgrade?
This is new issue related to #728. In #768 I fixed problem with composite keys. @rikvanderkemp reported another bug. ProxyQuery
adds columns from OrderBy to Select to be SQL compliant. But if column in OrderBy is an association, it should be added to Select as IDENTITY(id).
Current DQL: SELECT DISTINCT m.id, m.root, m.lft, m.id FROM MenuBundle\Entity\Menu m ORDER BY m.root ASC, m.lft ASC, m.id ASC
Valid DQL: SELECT DISTINCT m.id, IDENTITY(m.root) as root, m.lft, m.id FROM MenuBundle\Entity\Menu m ORDER BY m.root ASC, m.lft ASC, m.id ASC
For class Menu from case above:
$metadata = {Doctrine\ORM\Mapping\ClassMetadata} [40]
name = "MenuBundle\Entity\Menu"
identifier = {array} [1]
0 = "id"
fieldMappings = {array} [8]
id = {array} [9]
title = {array} [8]
subtitle = {array} [8]
url = {array} [8]
active = {array} [9]
lft = {array} [8]
lvl = {array} [8]
rgt = {array} [8]
associationMappings = {array} [3]
root = {array} [19]
parent = {array} [19]
children = {array} [16]
So, associationMappings in OrderBy should be detected and handled in different way.
Subject
I've got entity with foreing relation as id:
Sonata admin list page for this entity worket well,
but after composer update (sonata-doctrine-orm from 3.1.6 to 3.2.0) it stop worked with error: Invalid PathExpression. Must be a StateFieldPathExpression. Error is somewhere in query: SELECT DISTINCT IDENTITY(o.Region) as Region, o.Region FROM Myorg\SearchBundle\Entity\RegionSettings o ORDER BY o.Region ASC
I've updated to "sonata-project/doctrine-orm-admin-bundle": "3.1.*" and error is gone
Steps to reproduce
1) Create entity with assosiation-key, 2) create admin for that entity, 3) use 3.2.0 of sonata doctrine orm admin bunlde
Expected results
Admin list working
Actual results
Admin list NOT working
Environment
ubuntu 16.04
Sonata packages
Symfony packages
PHP version