Skip to content
Snippets Groups Projects
Unverified Commit d88e8d25 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2956556 by johndevman, daffie, Neslee Canil Pinto, dan.munn, aleevas,...

Issue #2956556 by johndevman, daffie, Neslee Canil Pinto, dan.munn, aleevas, dubcanada, alexpott: class isn't set in FETCH_OBJECT when class_name isn't set

(cherry picked from commit b2a10193)
parent 90a553d6
No related branches found
No related tags found
9 merge requests!1445Issue #2920039: Views' User Name exposed group filter validation,!1298Issue #3240993: Let layout builder render inline block translations,!774Issue #3174569: Example node template file name is incorrect,!497Issue #2463967: Use .user.ini file for PHP settings,!433Resolve #3163663 "Too many open files",!233Resolve #2693787 "Taxonomy term name",!133Resolve #2666286 "Clean up menuui",!112Resolve #3187004 "Drupaldatetime serialization issue",!53Resolve #3181870: Correct typo "the the" in "core/classList" deprecation message.
......@@ -417,7 +417,10 @@ public function fetchObject($class_name = NULL, $constructor_args = []) {
}
else {
$this->fetchStyle = \PDO::FETCH_CLASS;
$this->fetchOptions = ['constructor_args' => $constructor_args];
$this->fetchOptions = [
'class' => $class_name,
'constructor_args' => $constructor_args,
];
// Grab the row in the format specified above.
$result = $this->current();
// Reset the fetch parameters to the value stored using setFetchMode().
......
......@@ -80,6 +80,23 @@ public function testQueryFetchClass() {
$this->assertIdentical(count($records), 1, 'There is only one record.');
}
/**
* Confirms that we can fetch a record into a class using fetchObject.
*
* @see \Drupal\system\Tests\Database\FakeRecord
* @see \Drupal\Core\Database\StatementPrefech::fetchObject
*/
public function testQueryFetchObjectClass() {
$records = 0;
$query = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25]);
while ($result = $query->fetchObject(FakeRecord::class)) {
$records += 1;
$this->assertInstanceOf(FakeRecord::class, $result);
$this->assertSame('John', $result->name, '25 year old is John.');
}
$this->assertSame(1, $records, 'There is only one record.');
}
/**
* Confirms that we can fetch a record into a new instance of a custom class.
* The name of the class is determined from a value of the first column.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment