Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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 into
laravel:5.2from
melloc01:postgres-processor-pdo-fetch-class-sequence-access-fix
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
taylorotwell merged 1 commit into
laravel:5.2from
melloc01:postgres-processor-pdo-fetch-class-sequence-access-fix

Conversation

@melloc01
Copy link
Copy Markdown
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
Copy Markdown
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