MDL-79574 core: index returned persistent instances on record ID.

This commit is contained in:
Paul Holden
2026-02-27 10:30:09 +00:00
parent dcf942624d
commit b62750dd83
2 changed files with 12 additions and 6 deletions
@@ -0,0 +1,7 @@
issueNumber: MDL-79574
notes:
core:
- message: >-
The `\core\persistent::get_records(...)` class method now returns
instances keyed by record ID
type: changed
+5 -6
View File
@@ -842,11 +842,11 @@ abstract class persistent {
}
$records = $DB->get_records(static::TABLE, $filters, $orderby, '*', $skip, $limit);
$instances = array();
foreach ($records as $record) {
$newrecord = new static(0, $record);
array_push($instances, $newrecord);
// We return class instances.
$instances = [];
foreach ($records as $key => $record) {
$instances[$key] = new static(0, $record);
}
return $instances;
}
@@ -883,11 +883,10 @@ abstract class persistent {
$records = $DB->get_records_select(static::TABLE, $select, $params, $sort, $fields, $limitfrom, $limitnum);
// We return class instances.
$instances = array();
$instances = [];
foreach ($records as $key => $record) {
$instances[$key] = new static(0, $record);
}
return $instances;
}