[5.2] PostgresProcessor::processInserGettId | array cast fails to get Id when PDO fetch mode is set to PDO::FETCH_CLASS #14115
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.
function processInsertGetId
How to reproduce:
PDO::FETCH_CLASS
choosing it to cast to a Class that does not have the attributes set directly to the object, like Eloquent models that uses the$attributes
propertyprocessInsertGetId
Description:
Casting the
$results[0]
to an array having PDO fetch mode set toPDO::FETCH_CLASS
and the chosen class implements magic methods to handle attributes getters and setters (like Eloquent Models) the function would throw an errorUndefined index {$sequence}
on the assignment:The problem occurs because the given object would be cast to an array that doesn't have the
"id"
key on its first level of keys.About the solution:
On my use cases $result is always an object (on any PDO fetch method) but I still tested it because I was not sure I was covering all the use cases.
Feel free to comment, improve or create a test for this function & PR.