Skip to content

fix(catalog-api): write child FK on hasVersion / hasConfiguration / hasSetup#4

Merged
mosoriob merged 1 commit intomainfrom
fix/fk-on-child-relationships
May 3, 2026
Merged

fix(catalog-api): write child FK on hasVersion / hasConfiguration / hasSetup#4
mosoriob merged 1 commit intomainfrom
fix/fk-on-child-relationships

Conversation

@mosoriob
Copy link
Copy Markdown
Contributor

@mosoriob mosoriob commented May 2, 2026

Summary

  • PUT /models with hasVersion (and PUT softwareversions with hasConfiguration, etc.) silently dropped the child FK update. Hasura row was created/updated but software_id stayed null, leaving the version orphaned from its parent model.
  • Root cause: registry only modeled object-FK and junction-array relationships. One-to-many FK relationships where the FK column lives on the child row had no metadata, so the junction loop in service.ts skipped them.
  • Fix: introduces optional childFkColumn on RelationshipConfig, tags the 10 affected relationships (hasVersion across softwares + 7 model subtypes, softwareversions.hasConfiguration, modelconfigurations.hasSetup), and extends create + update handlers to emit clear_<rel> / link_<rel> update_modelcatalog_<child> mutations (replace semantics).

Test plan

  • npm run build — green
  • npm test — 186/186 pass (was 178/178; +4 new integration tests for FK-on-child PUT/POST flow + empty-array clear-only path)
  • Manual UI repro: create a new software version through the UI; verify modelcatalog_software_version.software_id equals the parent model id in Hasura
  • Verify pre-existing flows (PUT models with junction-only fields like hasModelCategory) still work unchanged

…asSetup

PUT /models with hasVersion silently dropped the child FK update: the resource
registry described object-FK and junction-array relationships but had no
metadata for one-to-many relationships where the FK column lives on the child
row (software_version.software_id, configuration.software_version_id,
configuration.model_configuration_id). The junction loop in service.ts skipped
these arrays, so the parent _set ran but the child FK stayed null and the row
was orphaned.

Add an optional childFkColumn to RelationshipConfig and mark all FK-on-child
cases in the registry: hasVersion across softwares + 7 model subtypes,
softwareversions.hasConfiguration, modelconfigurations.hasSetup.

The PUT handler now emits clear_<rel> + link_<rel> update_<child_table>
mutations alongside the existing junction multi-root mutation (replace
semantics: clear FK on rows previously linked to this parent and not in the
new list, then set FK on the rows in the new list). The POST handler emits a
link_<rel> update so newly created parents pick up the child rows referenced
in the request body.

Adds 4 integration tests (PUT with hasVersion, PUT with empty hasVersion,
PUT softwareversions with hasConfiguration, POST softwares with hasVersion).
186 tests pass.
@mosoriob mosoriob merged commit bfd9fcd into main May 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant