Skip to content
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

[6.x] Fix plucking column name containing a space #31299

Merged
merged 2 commits into from
Jan 30, 2020

Conversation

shadoWalker89
Copy link
Contributor

@shadoWalker89 shadoWalker89 commented Jan 30, 2020

This PR fixes this #31298

Plucking a column that contains a space in it's name will fail

NoteRow::pluck('Identifiant groupe');

Will give this error

ErrorException : Undefined property: stdClass::$groupe`
 W:\projects\exam-laravel\src\exam-laravel\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:2330
 W:\projects\exam-laravel\src\exam-laravel\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:2302
 W:\projects\exam-laravel\src\exam-laravel\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:687

As you can see in the error the First word of the column name is striped Identifiant and only the second word groupe is being used.
The problem is that the Illuminate\Database\Query\Builder::stripTableForPluck() is splitting the column name by space to allow for plucking while using column alias.
This behavior was introduced in this commit 4fd6db1

The PR preserves the alias behavior and fixes column names with a space.
This PR changes the alias behavior from splitting by space to splitting by as keyword. It also takes into consideration that the developper could write AS in uppercase.
Existing tests are passing a new test was added to confirm that plucking columns with a space in the name works as well.

As for why i have space in the column names; It's due to me developing a new application based on a legacy app database and both should exist at the same time until porting the features of the legacy one is over.

@shadoWalker89 shadoWalker89 force-pushed the fix_pluck_column_with_space branch from 62d6d99 to d30b907 Compare January 30, 2020 08:00
@taylorotwell taylorotwell merged commit 2b0effc into laravel:6.x Jan 30, 2020
@shadoWalker89 shadoWalker89 deleted the fix_pluck_column_with_space branch January 30, 2020 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants