diff --git a/.upgradenotes/MDL-79574-2025123010115375.yml b/.upgradenotes/MDL-79574-2025123010115375.yml new file mode 100644 index 00000000000..4bb04444452 --- /dev/null +++ b/.upgradenotes/MDL-79574-2025123010115375.yml @@ -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 diff --git a/public/lib/classes/persistent.php b/public/lib/classes/persistent.php index 5ebe0076055..86c07747533 100644 --- a/public/lib/classes/persistent.php +++ b/public/lib/classes/persistent.php @@ -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; }