[5.2] PostgresProcessor::processInserGettId | array cast fails to get Id when PDO fetch mode is set to PDO::FETCH_CLASS#14115
Merged
taylorotwell merged 1 commit intoJun 24, 2016
Merged
Conversation
…get "sequence" from entity when fetch mode is set to PDO::FETCH_CLASS
Contributor
|
Looks good to me. Also you have inspired me #14121 :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 processInsertGetIdHow to reproduce:
PDO::FETCH_CLASSchoosing it to cast to a Class that does not have the attributes set directly to the object, like Eloquent models that uses the$attributespropertyprocessInsertGetIdDescription:
Casting the
$results[0]to an array having PDO fetch mode set toPDO::FETCH_CLASSand 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.