-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ambiguous column id when using Relation instead of Builder #283
Conversation
Took 13 minutes
@rappasoft seems that automatic tests are cancealed by some github policy |
src/Traits/WithBulkActions.php
Outdated
@@ -65,7 +65,7 @@ public function resetBulk(): void | |||
public function selectedRowsQuery() | |||
{ | |||
return (clone $this->rowsQuery()) | |||
->unless($this->selectAll, fn ($query) => $query->whereIn($query->qualifyColumn($this->primaryKey), $this->selected)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a reason you removed this one? Also, is there qualifyColumn documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn, I forgot to undo it, it was a try because I noticed that the test I wrote was succeeding with the old code. so I put the PR in draft while was writing a better test
just fixing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyway, qualifyColumn is not documented in official Laravel documentation, it was released with laravel 5.5.29:
https://laravel-news.com/laravel-5-5-29-released
but it simply does this:
public function qualifyColumn($column)
{
return $this->model->qualifyColumn($column);
}
and Model::qualifyColumn() adds the table name before the column name:
public function qualifyColumn($column)
{
if (Str::contains($column, '.')) {
return $column;
}
return $this->getTable().'.'.$column;
}
…on fix Took 27 minutes
@rappasoft I just rewrote my test table and RelationshipDatatableComponentTest in order to have an example that gives an error without this PR and it is fixed by adding qualifyColumn() |
Took 5 minutes
@rappasoft I noticed a slight issue when using bulk actions with a many to many Relation to generate data:
if the pivot table has an id field, the query will generate an integrity constraint violation when using the id column to filter data:
this happens when executing the
WithBulkActions::selectedRowsQuery()
andWithBulkActions::selectedKeys()
methods and can be avoided by letting laravel to qualify the primaryKey column:$this->primaryKey //id
would become:
$query->qualifyColumn($this->primaryKey) //students.id
this is a very rare case, but could happen