Skip to content

Commit

Permalink
Use model's qualified key name for update queries (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyDunn authored May 2, 2024
1 parent be0cb3f commit fb8a5d0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/SortableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down

0 comments on commit fb8a5d0

Please sign in to comment.