From 39b6778ec9a562c8d57ea90e76a9ccc844b4d70c Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Fri, 19 Jan 2024 17:09:12 -0500 Subject: [PATCH] Improve findForCoRecord (NOJIRA) --- app/src/Lib/Traits/PrimaryLinkTrait.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/Lib/Traits/PrimaryLinkTrait.php b/app/src/Lib/Traits/PrimaryLinkTrait.php index 42e4b92e1..995caca74 100644 --- a/app/src/Lib/Traits/PrimaryLinkTrait.php +++ b/app/src/Lib/Traits/PrimaryLinkTrait.php @@ -151,14 +151,14 @@ public function calculateCoForRecord(EntityInterface $entity, bool $original=fal * #since COmanage Registry v5.0.0 * @param int $id Record ID * @return int|null CO ID or null if not found + * @throws Cake\Datasource\Exception\RecordNotFoundException */ public function findCoForRecord(int $id): ?int { - // Pull the object to examine the primary links - $query = $this->findById($id); - - // This will throw an error on failure - return $this->calculateCoForRecord($query->firstOrFail()); + // Pull the object to examine the primary links. We might be asked to find the + // CO for a deleted object (eg: to add a history record, or to show an older + // value for an entity), so accept archived records. + return $this->calculateCoForRecord($this->get($id, ['archived' => true])); } /**