From 1f312f20eb965dde53c354cd7bd22bc98ade20cf Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Thu, 4 Sep 2025 12:48:30 +0300 Subject: [PATCH] Fix Breadcrumb failing linkTable query --- .../Controller/Component/BreadcrumbComponent.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/Controller/Component/BreadcrumbComponent.php b/app/src/Controller/Component/BreadcrumbComponent.php index 44e24920c..414c9b8e5 100644 --- a/app/src/Controller/Component/BreadcrumbComponent.php +++ b/app/src/Controller/Component/BreadcrumbComponent.php @@ -215,7 +215,17 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa $linkTable = TableRegistry::getTableLocator()->get($modelPath); $contain = method_exists($linkTable, $containsList) ? $linkTable->$containsList() : []; - $linkObj = $linkTable->get($link->value, ['contain' => $contain]); + // Use the table alias for query building (avoid plugin-qualified names in SQL) + $modelAlias = $linkTable->getAlias(); + + $modelNameForeignKey = StringUtilities::classNameToForeignKey($modelAlias); + $linkAttr = $link->attr == $modelNameForeignKey ? 'id' : $link->attr; + $linkObj = $linkTable + ->find() + ->where(["$modelAlias.$linkAttr" => $link->value]) + ->contain($contain) + ->firstOrFail(); + if($index) { // We need to determine the primary link of the parent, which might or might @@ -271,6 +281,9 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa catch(\Exception $e) { // If anything goes wrong we don't want to crash the entire page $this->llog('error', "Breadcrumbs failed: " . $e->getMessage()); + $this->llog( + 'error', + "Breadcrumbs failed: " . json_encode($e->getTrace(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); } }