Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/src/Lib/Util/TableUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ public static function treeTraversalFromPrimaryLink(
// qualify the FK using the requester table we're currently traversing
// but compare against the physical table name in the database.
$fkQualifiedModel = StringUtilities::foreignKeyToQualifiedModelName($col, $primaryLinkModelName);

// Don't re-enter a model already recorded (e.g. Groups.parent_id -> Groups.id)
// so that we don't clobber an entity's own ID with its parent's.
// We will only ever have one instance of a model in a subnavigation tab listing.
if (array_key_exists($fkQualifiedModel, $results)) {
continue;
}

$fkTargetTable = TableRegistry::getTableLocator()->get($fkQualifiedModel);

$fk_table = $fkTargetTable->getTable();
Expand Down Expand Up @@ -326,6 +334,13 @@ public static function treeTraversalFromId(string $modelName, int $id, array &$r
// qualify the FK using the requester table we're currently traversing
// but compare against the physical table name in the database.
$fkQualifiedModel = StringUtilities::foreignKeyToQualifiedModelName($col, $modelName);

// Same guard as treeTraversalFromPrimaryKey — don't re-enter a model we've already recorded.
// We will only ever have one instance of a model in a subnavigation tab listing.
if (array_key_exists($fkQualifiedModel, $results)) {
continue;
}

$fkTargetTable = TableRegistry::getTableLocator()->get($fkQualifiedModel);

$fk_table = $fkTargetTable->getTable();
Expand Down