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:
# PK
# FK
# Legacy PK (for audit)
# 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 FK section.
- Review naming consistency for model classes and relationship attributes; document exceptions when legacy table/view naming must be preserved.
Summary
There is an unnecessary and redundant FK relationship in
NMA_Radionuclidesthat 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 indb/nma_legacy.pyto reduce future mistakes.Example of the Issue
NMA_Radionuclidesdefines a directthingrelationship that is not needed, because it already links toChemistrySampleInfo, which in turn links toThing. This creates redundant linkage and can mislead developers about the intended association path.thingrelationship is duplicated, which overrides the earlierback_populatesdefinition and can break ORM expectations.Tasks to resovle issue
thingrelationship fromNMA_Radionuclidesand eliminate duplicate definitions. Ensure relationships use the intendedChemistrySampleInfo → Thinglinkage path.__tablename__, place PK/FK fields in this exact order:# PK# FK# Legacy PK (for audit)# Legacy FK (for audit)