Skip to content

Commit 9c51523

Browse files
Fixed ambagious id field error when using the append to top in some cases
1 parent 7546eb3 commit 9c51523

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
## [2.2.1](https://github.com/UndefinedOffset/SortableGridField/tree/2.2.1) (2023-05-08)
4+
[Full Changelog](https://github.com/UndefinedOffset/SortableGridField/compare/2.2.0...2.2.1)
5+
36
## [2.2.0](https://github.com/UndefinedOffset/SortableGridField/tree/2.2.0) (2023-05-08)
47
[Full Changelog](https://github.com/UndefinedOffset/SortableGridField/compare/2.1.0...2.2.0)
58

src/Forms/GridFieldSortableRows.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ protected function fixSortColumn($gridField, SS_List $dataList)
335335
} else if ($this->append_to_top) {
336336
if ($hasVersioned) {
337337
// For versioned objects, modify them with the ORM so that the *_versions table is updated
338-
$itemsToUpdate = $modelClass::get()->where(($list instanceof RelationList ? '"' . $list->foreignKey . '" = ' . $owner->ID : $idCondition) . (!empty($topIncremented) ? ' AND "ID" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
338+
$itemsToUpdate = $modelClass::get()->where(($list instanceof RelationList ? '"' . $list->foreignKey . '" = ' . $owner->ID : '"' . $table . '".' . $idCondition) . (!empty($topIncremented) ? ' AND "ID" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
339339
if ($itemsToUpdate->exists()) {
340340
foreach ($itemsToUpdate as $item) {
341341
$item->$sortColumn = $item->$sortColumn + 1;
@@ -346,13 +346,13 @@ protected function fixSortColumn($gridField, SS_List $dataList)
346346
//Upgrade all the records (including the last inserted from 0 to 1)
347347
DB::query('UPDATE "' . $table
348348
. '" SET "' . $sortColumn . '" = "' . $sortColumn . '"+1'
349-
. ' WHERE ' . ($list instanceof RelationList ? '"' . $list->foreignKey . '" = ' . $owner->ID : $idCondition) . (!empty($topIncremented) ? ' AND "ID" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
349+
. ' WHERE ' . ($list instanceof RelationList ? '"' . $list->foreignKey . '" = ' . $owner->ID : '"' . $table . '".' . $idCondition) . (!empty($topIncremented) ? ' AND "ID" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
350350
}
351351

352352
if ($this->update_versioned_stage && $this->hasVersionedExtension($gridField->getModelClass())) {
353353
DB::query('UPDATE "' . $table . '_' . $this->update_versioned_stage
354354
. '" SET "' . $sortColumn . '" = "' . $sortColumn . '"+1'
355-
. ' WHERE ' . ($list instanceof RelationList ? '"' . $list->foreignKey . '" = ' . $owner->ID : $idCondition) . (!empty($topIncremented) ? ' AND "ID" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
355+
. ' WHERE ' . ($list instanceof RelationList ? '"' . $list->foreignKey . '" = ' . $owner->ID : '"' . $table . '_' . $this->update_versioned_stage . '".' . $idCondition) . (!empty($topIncremented) ? ' AND "ID" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
356356
}
357357

358358
$topIncremented[] = $obj->ID;

0 commit comments

Comments
 (0)