# problem mit doctrine query seit sw 5.1.x (RuntimeException: Cannot select distinct identifiers from)

**URL:** <https://forum.shopware.com/t/problem-mit-doctrine-query-seit-sw-5-1-x-runtimeexception-cannot-select-distinct-identifiers-from/34219>\
**Category:** Programmierung\
**Created:** [4. Februar 2016 um 12:51 UTC](https://forum.shopware.com/t/problem-mit-doctrine-query-seit-sw-5-1-x-runtimeexception-cannot-select-distinct-identifiers-from/34219 "2016-02-04T12:51:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [4. Februar 2016 um 12:51 UTC](https://forum.shopware.com/t/problem-mit-doctrine-query-seit-sw-5-1-x-runtimeexception-cannot-select-distinct-identifiers-from/34219/1 "2016-02-04T12:51:45Z")

</div>

hallo zusammen,

seit sw 5.1.x geht ein&nbsp;doctrine query nicht mehr und ich komm nicht drauf warum.

lauft auf sw 4.3.x - 5.0.x ohne probleme.

folgendes wird gemacht:

per hook (Shopware\Models\Order\Repository::getBackendOrdersQueryBuilder::after)

lass ich mir den builder geben.

diesen erweitere ich mit einem select, leftJoin und orderBy.

jetzt bekomm ich diesen fehler wenn ich nach meinem select sortiere:

```
Fatal error: Uncaught exception 'RuntimeException' with message 'Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers.' in /var/www/clients/client2/web4/web/sw51/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php:149 Stack trace: #0 /var/www/clients/client2/web4/web/sw51/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php(74): Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker->validate(Object(Doctrine\ORM\Query\AST\SelectStatement)) #1 /var/www/clients/client2/web4/web/sw51/vendor/doctrine/orm/lib/Doctrine/ORM/Query/TreeWalkerChain.php(113): Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker->walkSelectStatement(Object(Doctrine\ORM\Query\AST\SelectStatement)) #2 /var/www/clients/client2/web4/web/sw51/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(380): Doctrine\ORM\Query\TreeWalkerChain->walkSelectStatement(Object(Doctrine\ORM\Query\AST\SelectStatement)) #3 /var/www/clients/cl in /var/www/clients/client2/web4/web/sw51/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php on line 149
503 Service Unavailable

```

nutz ich&nbsp;orderBy mit einem standard (z.b. orders.id) läufts wieder.

nur nicht mit meiner ergänzung.

kann mir einer auf die sprünge helfen, danke.

---

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [4. Februar 2016 um 14:24 UTC](https://forum.shopware.com/t/problem-mit-doctrine-query-seit-sw-5-1-x-runtimeexception-cannot-select-distinct-identifiers-from/34219/2 "2016-02-04T14:24:10Z")

</div>

// edit

hab noch etwas rumgetestet.

folgendes hab ich in der&nbsp;/engine/Shopware/Controllers/Backend/Order.php gemacht:

in der methode&nbsp;getList()&nbsp;

```
$sort = array(array('property' => 'details.id', 'direction' => 'DESC'));

```

als standard wert eingetragen und&nbsp;/backend/Order/getList ausgeführt.

- SW 5.0.x läuft

- SW 5.1.x fehler

- SW 5.0.x läuft

- SW 5.1.x läuft

**unterschied ist**

details

```
[details] => Array
(
	[0] => Array
	(
		[id] => 3
		...
	)

)

```

payment

```
[payment] => Array
(
	[id] => 5
	...
)

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [10. Februar 2016 um 10:34 UTC](https://forum.shopware.com/t/problem-mit-doctrine-query-seit-sw-5-1-x-runtimeexception-cannot-select-distinct-identifiers-from/34219/3 "2016-02-10T10:34:51Z")

</div>

\* push

liebes SWAG team,

könnte sich das mal jemand ansehen und sagen warum sich das verhalten geändert hat&nbsp;und deshalb ein fehler ausgegeben&nbsp;wird.  
ich hab leider keine lösung gefunden ☹

---

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [17. Februar 2016 um 11:42 UTC](https://forum.shopware.com/t/problem-mit-doctrine-query-seit-sw-5-1-x-runtimeexception-cannot-select-distinct-identifiers-from/34219/4 "2016-02-17T11:42:57Z")

</div>

tach zusammen,

wäre jemand so nett und könnte folgende query mal ab V 5.1.1 testen:

```
// geht nicht bei 5.1.x, aber auf 5.0.x
$sort = array(array('property' => 'details.id', 'direction' => 'DESC'));
// default geht
//$sort = array(array('property' => 'orders.id', 'direction' => 'DESC'));

$builder = Shopware()->Models()->createQueryBuilder();
$builder->select(array(
	'orders',
	'details',
	'customer',
	'payment',
	'billing',
	'billingCountry',
	'billingState',
	'shop',
	'dispatch',
	'paymentStatus',
	'orderStatus',
	'billingAttribute',
	'attribute'
));

$builder->from('Shopware\Models\Order\Order', 'orders');
$builder->leftJoin('orders.payment', 'payment')
		->leftJoin('orders.paymentStatus', 'paymentStatus')
		->leftJoin('orders.orderStatus', 'orderStatus')
		->leftJoin('orders.billing', 'billing')
		->leftJoin('orders.customer', 'customer')
		->leftJoin('orders.details', 'details')
		->leftJoin('billing.country', 'billingCountry')
		->leftJoin('billing.state', 'billingState')
		->leftJoin('orders.shop', 'shop')
		->leftJoin('orders.dispatch', 'dispatch')
		->leftJoin('billing.attribute', 'billingAttribute')
		->leftJoin('orders.attribute', 'attribute')
		->setFirstResult(0)
		->setMaxResults(10)
		->addOrderBy($sort);

$query = $builder->getQuery();
$query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
$paginator = $this->getModelManager()->createPaginator($query);
$total = $paginator->count();
die(''.print_r($paginator->getIterator()->getArrayCopy(), true).'');

```

&nbsp;
