You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5a4c815
Browse filesBrowse the repository at this point in the historyBrowse files
fix(codegen-kotlin): fold TPH discriminator subtypes into the base — no dead per-subtype artifacts
A TPH (table-per-hierarchy) discriminator base already emitted the union table +
data class + discriminator enum + polymorphic controller, and the controller
generator skipped subtypes — but five other generation paths still emitted dead,
partly non-compiling per-subtype artifacts for each subtype:
- KotlinExposedTableGenerator emitted <Sub>Table mapping the SAME physical table
with a partial column set (a footgun), AND its back-FK inference
(buildGlobalFkMap) fanned a base's inherited to-many composition into phantom
per-subtype inverse FKs (<Sub>Table.id references) — a compile break once the
tables are folded away.
- KotlinEntityGenerator emitted a dead <Sub> data class that re-emitted the
inherited discriminator enum under a spurious name.
- KotlinFilterAllowlistGenerator / KotlinValidatorGenerator / KotlinRelationsGenerator
emitted dead <Sub> allowlists / registry entries / relation helpers, the latter
two referencing the now-missing <Sub>Table (compile breaks).
Fix: every entity-iterating generator now skips KotlinTphPlan.isTphSubtype (mirroring
the controller's existing skip). Because a subtype folds into the base, the base
union data class must also emit the enum class for any subtype-only field.enum it
folds in (KotlinEntityGenerator now emits enum files over collectSubtypeFields,
owner = base) — else the union references an enum no file defines.
This brings Kotlin into line with the Java (codegen-spring) port, which already
folds TPH subtypes into the base.
Gated:
- Expanded entity-with-tph snapshot fixture (a to-many composition Auth.lines→AuthLine
+ validator/relations generators) byte-gates the five structural skips + the
buildGlobalFkMap fold — reverting any one re-emits a per-subtype artifact.
- New KotlinOutputCompilesTest case compile-proves the folded-subtype-enum path
(a subtype field.enum → the base union compiles).
- New integration TphFullSuiteCompilesTest compiles the FULL generator suite
(Exposed + Spring on the classpath) over a discriminator base owning a
composition — the compile gate the snapshot byte-compare can't provide.
Scoped out: a pre-existing, non-TPH bug where the generated Kotlin controller emits
non-compiling enum-filter code for @filterable field.enum columns (wrong enum name +
String→enum cast) — filed as #179; this change keeps its snapshot fixture's subtype
enum off the controller surface.
Two rounds of code review + simplify informed this change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ew1XfYSbEAezxjs9opynAe
Copy file name to clipboardExpand all lines: server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinExposedTableGenerator.kt
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,11 @@ open class KotlinExposedTableGenerator : MultiFileDirectGeneratorBase<MetaObject
Copy file name to clipboardExpand all lines: server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinFilterAllowlistGenerator.kt
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,10 @@ open class KotlinFilterAllowlistGenerator : MultiFileDirectGeneratorBase<MetaObj
55
55
val outRoot =Paths.get(outDir.absolutePath)
56
56
for (entity in loader.metaObjects) {
57
57
if (entity.subType !=MetaObject.SUBTYPE_ENTITY) continue
58
+
// FR-017 TPH: a discriminator subtype folds into its base — the base's allowlist
59
+
// (unioned across subtype columns via isTphBase) is the only one the polymorphic
60
+
// controller uses; a per-subtype allowlist is dead. Mirror the controller/table skip.
61
+
if (KotlinTphPlan.isTphSubtype(entity)) continue
58
62
// ADR-0039: resolving source lookup (inherited source.rdb via extends).
59
63
val sourceRdb =KotlinGenUtil.firstRdbSource(entity) ?:continue
60
64
// Only writable tables get a filter allowlist (the controller is also
0 commit comments