-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.2] Support composite column names like 'table.id' in chunkById #14499
Conversation
This does not work until laravel/framework#14499 is resolved! References #4
I worry this will create very unexpected behavior. For example if you select two columns with the same name and the last one specified is the one taken, then use this |
@@ -1763,13 +1763,14 @@ public function chunkById($count, callable $callback, $column = 'id') | |||
$lastId = null; | |||
|
|||
$results = $this->forPageAfterId($count, 0, $column)->get(); | |||
$columnSuffix = last(explode('.', $column)); |
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.
Wouldn't PHP throw a warning about not providing a reference here?
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.
Interesting point, one would certainly expect so. Apparently being wrapped in the helper function prevents the warning since this creates a new variable.
@taylorotwell Yes, you have a point. But it's not just trying to be fancy here, since my first example currently does not work (although one might expect it to) and my "workaround" with the alias only works with SQLite (as far as I know). Standard SQL doesn't allow a column alias in a What do you think of adding an optional fourth parameter to DB::table('annotations')
->join('images', 'annotations.image_id', '=', 'images.id')
->where(/* something with images */)
->select('annotations.id as annotations_id', /* ... */)
->chunkById(500, $handleChunk, 'annotations.id', 'annotations_id'); |
Example use case that didn't work before:
As a workaround I used an alias for the ambiguous column:
But PostgreSQL for example doesn't allow the use of an alias in a
where
statement like it is built bychunkById
.