Skip to content

Commit a56f455

Browse files
committed
Allow inserts on ContainerScopedTable when pseudo-key is the real PK
ContainerScopedTable.init() hid and disabled every real PK column, assuming the real PK is always a surrogate key. When the pseudo-key is also the real PK (a natural key, like ehr_lookups.project_types.type), this made the key column hidden and non-editable, so inserts were impossible. Detect that case and leave the column visible and editable, hiding it only from the update form.
1 parent c5baffb commit a56f455

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

LDK/api-src/org/labkey/api/ldk/table/ContainerScopedTable.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,37 @@ public ContainerScopedTable<SchemaType> init()
8080
{
8181
super.init();
8282

83+
boolean realPkIsPseudoKey = false;
8384
for (String col : getRealTable().getPkColumnNames())
8485
{
8586
var existing = getMutableColumn(col);
8687
if (existing != null)
8788
{
88-
existing.setKeyField(false);
89-
existing.setUserEditable(false);
90-
existing.setHidden(true);
9189
_realPKs.add(col);
90+
if (col.equalsIgnoreCase(_pseudoPk))
91+
{
92+
// The pseudo-key is also the real PK (a natural key, like ehr_lookups.project_types.type),
93+
// so it must remain visible and editable for inserts to be possible
94+
realPkIsPseudoKey = true;
95+
}
96+
else
97+
{
98+
existing.setKeyField(false);
99+
existing.setUserEditable(false);
100+
existing.setHidden(true);
101+
}
92102
}
93103
}
94104

95105
var newKey = getMutableColumn(_pseudoPk);
96106
assert newKey != null;
97107

98108
newKey.setKeyField(true);
109+
if (realPkIsPseudoKey)
110+
{
111+
// Enterable on insert, but hidden from the update form
112+
newKey.setShownInUpdateView(false);
113+
}
99114
return this;
100115
}
101116

0 commit comments

Comments
 (0)