[6.x] Fix plucking column name containing a space #31299
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes this #31298
Plucking a column that contains a space in it's name will fail
Will give this error
As you can see in the error the First word of the column name is striped
Identifiant
and only the second wordgroupe
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 writeAS
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.