Chemical-Curation / chemcurator_django

Backend services for chemical curation
https://api.chemreg.epa.gov
MIT License
1 stars 0 forks source link

substance compound 1:1 #235

Closed cmgrulke closed 3 years ago

cmgrulke commented 3 years ago

As a cheminformatian I want substances and compounds to have a 1:1 relationship So that a single structural depiction cannot be erroneously linked to multiple substances and a substance cannot be depicted erroneously with different structures.

Acceptance Criteria: the relationship between substances and compounds is 0/1 : 0/1

Test:

michael-barbour commented 3 years ago

This ticket can be closed. I made this change in #231 due to this being a probable blocker.

The code is here on the substance model chemreg/substance/models.py line 121

associated_compound = models.OneToOneField(
    "compound.BaseCompound",
    on_delete=models.PROTECT,
    null=True,
    related_name="substance",
)

and on the substance migration _chemreg/substance/migrations/0007_orionsprint.py line 47

migrations.AlterField(
    model_name='substance',
    name='associated_compound',
    field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='substance', to='compound.BaseCompound'),
),

Note: It looks like our api somewhat subverts this using the "replaced_by" redirects and soft deletes. The request from ticket #39 makes no restriction that the compound that is being forwarded to cannot be directly bound to a substance.

A substance can be directly associated with a compound "replacing" another and any number of compounds can point to a single compound as the replacement. This breaks the 1 - 1 principle but is not what this ticket was originally about.

**edit: Upon further inspection it looks like the /substances endpoint does not return the connection to compounds that have replaced_by set to another compound. This seems to be working properly.

debboutr commented 3 years ago

@michael-barbour this makes sense, I guess if replaced_by is not null, it will have to point to that compound.

Thanks for getting this done!

jtumkur commented 3 years ago

Did not required code change as part #54