From b62750dd8310aa08cd99276c63b1d583e33dd201 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 17 Dec 2024 14:55:17 +0000 Subject: [PATCH] MDL-79574 core: index returned persistent instances on record ID. --- .upgradenotes/MDL-79574-2025123010115375.yml | 7 +++++++ public/lib/classes/persistent.php | 11 +++++------ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .upgradenotes/MDL-79574-2025123010115375.yml 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; }