From 6db3b8e996dcc13652379bf3f1e93ed6dc682380 Mon Sep 17 00:00:00 2001 From: Jeremy Dunn Date: Sun, 28 Apr 2024 09:05:47 -0500 Subject: [PATCH] Use model's qualified key name for update queries --- src/SortableTrait.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SortableTrait.php b/src/SortableTrait.php index 9b02e45..b3a6cd3 100644 --- a/src/SortableTrait.php +++ b/src/SortableTrait.php @@ -51,7 +51,7 @@ public static function setNewOrder($ids, int $startOrder = 1, string $primaryKey $orderColumnName = $model->determineOrderColumnName(); if (is_null($primaryKeyColumn)) { - $primaryKeyColumn = $model->getKeyName(); + $primaryKeyColumn = $model->getQualifiedKeyName(); } if (config('eloquent-sortable.ignore_timestamps', false)) { @@ -157,7 +157,7 @@ public function moveToStart(): static $this->$orderColumnName = $firstModel->$orderColumnName; $this->save(); - $this->buildSortQuery()->where($this->getKeyName(), '!=', $this->getKey())->increment($orderColumnName); + $this->buildSortQuery()->where($this->getQualifiedKeyName(), '!=', $this->getKey())->increment($orderColumnName); return $this; } @@ -177,7 +177,7 @@ public function moveToEnd(): static $this->$orderColumnName = $maxOrder; $this->save(); - $this->buildSortQuery()->where($this->getKeyName(), '!=', $this->getKey()) + $this->buildSortQuery()->where($this->getQualifiedKeyName(), '!=', $this->getKey()) ->where($orderColumnName, '>', $oldOrder) ->decrement($orderColumnName);