Skip to content

Commit

Permalink
Qualify pivot column name
Browse files Browse the repository at this point in the history
Prevents collision with local column name, eg, pivot[sort_order] & related[sort_order]
  • Loading branch information
octoberapp committed Nov 29, 2023
1 parent a67c128 commit dfcc9b2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Database/Traits/SortableRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ public function initializeSortableRelation()
return;
}

$relation = $this->$relationName();

$column = $this->getRelationSortOrderColumn($relationName);

$order = $this->$relationName()->max($column);
$order = $relation->max($relation->qualifyPivotColumn($column));

foreach ((array) $attached as $id) {
$this->$relationName()->updateExistingPivot($id, [$column => ++$order]);
$relation->updateExistingPivot($id, [$column => ++$order]);
}
});
}
Expand Down

0 comments on commit dfcc9b2

Please sign in to comment.