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

[5.2] PostgresProcessor::processInserGettId | array cast fails to get Id when PDO fetch mode is set to PDO::FETCH_CLASS #14115

Merged
merged 1 commit into from
Jun 24, 2016
Merged

[5.2] PostgresProcessor::processInserGettId | array cast fails to get Id when PDO fetch mode is set to PDO::FETCH_CLASS #14115

merged 1 commit into from
Jun 24, 2016

Conversation

melloc01
Copy link
Contributor

function processInsertGetId

How to reproduce:

  • Enable PDO fetch mode set to 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 property
  • Use processInsertGetId

Description:
Casting the $results[0] to an array having PDO fetch mode set to PDO::FETCH_CLASS and the chosen class implements magic methods to handle attributes getters and setters (like Eloquent Models) the function would throw an error Undefined index {$sequence} on the assignment:

$id = $result[$sequence];

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.

…get "sequence" from entity when fetch mode is set to PDO::FETCH_CLASS
@GrahamCampbell GrahamCampbell changed the title PostgresProcessor::processInserGettId | array cast fails to get Id when PDO fetch mode is set to PDO::FETCH_CLASS [5.2] PostgresProcessor::processInserGettId | array cast fails to get Id when PDO fetch mode is set to PDO::FETCH_CLASS Jun 23, 2016
@vlakoff
Copy link
Contributor

vlakoff commented Jun 23, 2016

Looks good to me. Also you have inspired me #14121 :)

@taylorotwell taylorotwell merged commit 6ad7db4 into laravel:5.2 Jun 24, 2016
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.

3 participants