Skip to content

Commit

Permalink
Qualify orderBy column with table name to avoid conflicts (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin authored May 16, 2024
1 parent 9e9c3a5 commit cf8fd34
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Database/SortableScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function apply(BuilderBase $builder, ModelBase $model)
{
// Only apply the scope when no other explicit orders have been set
if (empty($builder->getQuery()->orders) && empty($builder->getQuery()->unionOrders)) {
$builder->orderBy($model->getSortOrderColumn());
$builder->orderBy($model->qualifyColumn($model->getSortOrderColumn()));
}
}
}
4 changes: 2 additions & 2 deletions tests/Database/SortableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public function testOrderByIsAutomaticallyAdded()
$model = new TestSortableModel();
$query = $model->newQuery()->toSql();

$this->assertEquals('select * from "test" order by "sort_order" asc', $query);
$this->assertEquals('select * from "test" order by "test"."sort_order" asc', $query);
}

public function testCustomSortOrderByIsAutomaticallyAdded()
{
$model = new TestCustomSortableModel();
$query = $model->newQuery()->toSql();

$this->assertEquals('select * from "test" order by "rank" asc', $query);
$this->assertEquals('select * from "test" order by "test"."rank" asc', $query);
}

public function testOrderByCanBeOverridden()
Expand Down

1 comment on commit cf8fd34

@LukeTowers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bennothommo can you take a look at the code analysis run for this commit?

Please sign in to comment.