Skip to content

Commit 2c65138

Browse files
committed
MAGETWO-95315: [2.3] Joins to grid collections causes MySQL exception due to ambiguous where clause
1 parent 8460e4e commit 2c65138

File tree

2 files changed

+60
-0
lines changed
  • app/code/Magento/Sales/Model/ResourceModel/Order/Grid
  • dev/tests/integration/testsuite/Magento/Sales/Model/ResourceModel/Order/Grid

2 files changed

+60
-0
lines changed

app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,19 @@ public function __construct(
3535
) {
3636
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
3737
}
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
protected function _initSelect()
43+
{
44+
parent::_initSelect();
45+
46+
$tableDescription = $this->getConnection()->describeTable($this->getMainTable());
47+
foreach ($tableDescription as $columnInfo) {
48+
$this->addFilterToMap($columnInfo['COLUMN_NAME'], 'main_table.' . $columnInfo['COLUMN_NAME']);
49+
}
50+
51+
return $this;
52+
}
3853
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Model\ResourceModel\Order\Grid;
9+
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
class CollectionTest extends \PHPUnit\Framework\TestCase
13+
{
14+
/**
15+
* Tests collection properties.
16+
*
17+
* @throws \ReflectionException
18+
* @return void
19+
*/
20+
public function testCollectionCreate(): void
21+
{
22+
$objectManager = Bootstrap::getObjectManager();
23+
24+
/** @var Collection $gridCollection */
25+
$gridCollection = $objectManager->get(Collection::class);
26+
$tableDescription = $gridCollection->getConnection()
27+
->describeTable($gridCollection->getMainTable());
28+
29+
$mapper = new \ReflectionMethod(
30+
Collection::class,
31+
'_getMapper'
32+
);
33+
$mapper->setAccessible(true);
34+
$map = $mapper->invoke($gridCollection);
35+
36+
self::assertInternalType('array', $map);
37+
self::assertArrayHasKey('fields', $map);
38+
self::assertInternalType('array', $map['fields']);
39+
self::assertCount(count($tableDescription), $map['fields']);
40+
41+
foreach ($map['fields'] as $mappedName) {
42+
self::assertContains('main_table.', $mappedName);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)