From fb8a5d071eec525cd5a0ad1a011306c0a76b2a9f Mon Sep 17 00:00:00 2001 From: Jeremy Dunn Date: Thu, 2 May 2024 04:49:34 -0500 Subject: [PATCH] Use model's qualified key name for update queries (#175) --- 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);