Skip to content

Remove redundant Thing FK in NMA_Radionuclides and standardize PK/FK layout #461

@ksmuczynski

Description

@ksmuczynski

Summary

There is an unnecessary and redundant FK relationship in NMA_Radionuclides that adds confusion and risks masking the real FK path, creating confusion in ORM behavior and usage. While addressing it, we should also standardize PK/FK placement and naming in db/nma_legacy.py to reduce future mistakes.

Example of the Issue

  • NMA_Radionuclides defines a direct thing relationship that is not needed, because it already links to ChemistrySampleInfo, which in turn links to Thing. This creates redundant linkage and can mislead developers about the intended association path.
  • That same thing relationship is duplicated, which overrides the earlier back_populates definition and can break ORM expectations.
  • PK/FK fields are defined in multiple positions depending on the model rather than consistently grouped, and naming varies across the file.

Tasks to resovle issue

  • Remove the unnecessary thing relationship from NMA_Radionuclides and eliminate duplicate definitions. Ensure relationships use the intended ChemistrySampleInfo → Thing linkage path.
  • Add a file-wide convention: under each __tablename__, place PK/FK fields in this exact order:
  1. # PK
  2. # FK
  3. # Legacy PK (for audit)
  4. # Legacy FK (for audit)
  • Move all PK/FK fields to the top of each model, immediately under the table name.
  • Ensure legacy UUID FKs are labeled and grouped under the # Legacy UUID FK section.
  • Review naming consistency for model classes and relationship attributes; document exceptions when legacy table/view naming must be preserved.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions