From 89f648928f4fc36491a5cb2119338a5cbb94298b Mon Sep 17 00:00:00 2001 From: Michael Dieringer <65093775+MichaelDieringer@users.noreply.github.com> Date: Tue, 22 Sep 2026 20:59:56 +0200 Subject: [PATCH] Give the table-relation-test fixtures a real relation to exclude and one to protect The "Category Code" field had no TableRelation at all, so the good subscriber's RemoveTableRelation call targeted metadata that never existed - a no-op. Added a real TableRelation to "Sample Setup" on that field (the one known exception to exclude) and a second, ordinary self-referencing relation ("Parent No." -> "Sample Header"."No.") with no exception. The good fixture now removes only the first; the bad fixture's table-wide removal (field/related table/field all 0) now demonstrably also strips the second, showing the actual anti-pattern instead of removing nothing meaningful. --- ...e-known-invalid-relations-via-event.bad.al | 14 +++++++++++-- ...-known-invalid-relations-via-event.good.al | 20 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/microsoft/knowledge/testing/table-relation-test-exclude-known-invalid-relations-via-event.bad.al b/microsoft/knowledge/testing/table-relation-test-exclude-known-invalid-relations-via-event.bad.al index 1550350..d95d9f2 100644 --- a/microsoft/knowledge/testing/table-relation-test-exclude-known-invalid-relations-via-event.bad.al +++ b/microsoft/knowledge/testing/table-relation-test-exclude-known-invalid-relations-via-event.bad.al @@ -16,7 +16,14 @@ table 50145 "Sample Header" fields { field(1; "No."; Code[20]) { } - field(10; "Category Code"; Code[20]) { } + field(10; "Category Code"; Code[10]) + { + TableRelation = "Sample Setup"."Primary Key"; + } + field(11; "Parent No."; Code[20]) + { + TableRelation = "Sample Header"."No."; + } } keys { @@ -31,7 +38,10 @@ codeunit 50141 "Sample Table Relation Test Ext" var TableRelationTest: Codeunit "Table Relation Test"; begin - // Removes every relation on the whole table, not just the one known exception + // Removes every relation on the whole table (field/related table/ + // related field all 0), not just the one known exception - this + // also strips "Parent No." -> "Sample Header"."No.", which had no + // exception and should have stayed covered by the standard test. TableRelationTest.RemoveTableRelation(TableRelationsMetadata, Database::"Sample Header", 0, 0, 0); end; } diff --git a/microsoft/knowledge/testing/table-relation-test-exclude-known-invalid-relations-via-event.good.al b/microsoft/knowledge/testing/table-relation-test-exclude-known-invalid-relations-via-event.good.al index 0a6d480..26db161 100644 --- a/microsoft/knowledge/testing/table-relation-test-exclude-known-invalid-relations-via-event.good.al +++ b/microsoft/knowledge/testing/table-relation-test-exclude-known-invalid-relations-via-event.good.al @@ -16,10 +16,20 @@ table 50145 "Sample Header" fields { field(1; "No."; Code[20]) { } - // A known exception: this field is allowed to reference "Sample - // Setup" loosely (no TableRelation enforced here on purpose), so - // the standard Table Relation Test would otherwise reject it. - field(10; "Category Code"; Code[20]) { } + // A known exception: "Category Code" predates "Sample Setup" and + // can carry a value that no longer resolves to a real row there, + // so the standard Table Relation Test would otherwise reject it - + // excluded via OnAfterRemoveTableRelation below. + field(10; "Category Code"; Code[10]) + { + TableRelation = "Sample Setup"."Primary Key"; + } + // An ordinary relation with no exception - ExcludeSampleFieldFrom + // TableRelationTest below must leave this one checked. + field(11; "Parent No."; Code[20]) + { + TableRelation = "Sample Header"."No."; + } } keys { @@ -34,6 +44,8 @@ codeunit 50141 "Sample Table Relation Test Ext" var TableRelationTest: Codeunit "Table Relation Test"; begin + // Removes only the one known exception. "Parent No." -> "Sample + // Header"."No." is untouched and stays covered by the standard test. TableRelationTest.RemoveTableRelation(TableRelationsMetadata, Database::"Sample Header", 10, Database::"Sample Setup", 1); end; }