Skip to content

Create nested associations in emodel and campaigns#545

Merged
GianlucaFicarelli merged 2 commits intomainfrom
create_nested_associations
Mar 5, 2026
Merged

Create nested associations in emodel and campaigns#545
GianlucaFicarelli merged 2 commits intomainfrom
create_nested_associations

Conversation

@GianlucaFicarelli
Copy link
Collaborator

@GianlucaFicarelli GianlucaFicarelli commented Mar 5, 2026

This PR allows to create or update nested associations:

  • IonChannelModelToEModel
  • IonChannelRecordingToIonChannelModelingCampaign (although it should be removed in favor of using TaskConfig)
  • EmCellMeshToSkeletonizationCampaign (although it should be removed in favor of using TaskConfig)

Note:

  1. the associations can be created in the same POST request that creates the main entity (EModel, IonChannelModelingCampaign, SkeletonizationCampaign)
  2. the associations can be updated with a PATCH request after the main entity has been created, but only if there aren't associations already
  3. the associations can be removed only when the main entity is removed

If needed, we can create a separate PR to allow:

  1. modifying (replacing) the associations with a PATCH request when they exist already
  2. removing the associations without deleting the main entity (same PATCH request as in the previous point, but with empty list of associations)

See https://github.com/openbraininstitute/prod-human-data-and-models/issues/15#issuecomment-3983670537 and the following comments.

@GianlucaFicarelli GianlucaFicarelli self-assigned this Mar 5, 2026
"""Callable that should accept parent_id and child_id and return a valid db model instance."""

def __call__(self, *, left_id: uuid.UUID, right_id: uuid.UUID) -> DeclarativeBase: ...
def __call__(self, *, parent_id: uuid.UUID, child_id: uuid.UUID) -> DeclarativeBase: ...
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed left_id to parent_id and right_id to child_id because it seems easier to understand what are the relationships: parent refers to the main entity, and child refer to one of the many children.
Please let me know if you find it clear enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it is more intuitive this way

TaskConfig: {
"inputs": {
"relationship_name": "inputs",
"db_model_factory": lambda *, parent_id, child_id: TaskConfigToEntity(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the name of the association table TaskConfigToEntity, the order of the entities is inverted compared to the other association tables below:

  • IonChannelModelToEModel
  • IonChannelRecordingToIonChannelModelingCampaign
  • EmCellMeshToSkeletonizationCampaign

I'm considering to rename TaskConfigToEntity to EntityToTaskConfig to use the same naming convention.
It requires a new schema migration, but the table isn't used yet.
Thoughts?

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
pytest 97.91% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
app/queries/common.py 98.00% <100.00%> (+0.05%) ⬆️
app/queries/constants.py 100.00% <100.00%> (ø)
app/queries/types.py 100.00% <ø> (ø)
app/queries/utils.py 92.85% <100.00%> (ø)
app/schemas/emodel.py 100.00% <100.00%> (ø)
app/schemas/ion_channel_modeling_campaign.py 100.00% <100.00%> (ø)
app/schemas/skeletonization_campaign.py 100.00% <100.00%> (ø)
app/service/emodel.py 100.00% <ø> (ø)
app/service/task_config.py 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@GianlucaFicarelli GianlucaFicarelli merged commit dfb3246 into main Mar 5, 2026
2 checks passed
@GianlucaFicarelli GianlucaFicarelli deleted the create_nested_associations branch March 5, 2026 17:31
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.

2 participants