Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions app/service/emodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ETypeClass,
ETypeClassification,
IonChannelModel,
IonChannelModelToEModel,
MTypeClass,
MTypeClassification,
ReconstructionMorphology,
Expand Down Expand Up @@ -46,6 +47,11 @@ def _load(select: sa.Select[tuple[EModel]]):
selectinload(EModel.contributions).joinedload(Contribution.role),
joinedload(EModel.mtypes),
joinedload(EModel.etypes),
selectinload(EModel.assets),
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.species),
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.strain),
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.brain_region),
selectinload(EModel.ion_channel_models).selectinload(IonChannelModel.assets),
raiseload("*"),
)

Expand All @@ -55,23 +61,13 @@ def read_one(
db: SessionDep,
id_: uuid.UUID,
) -> EModelReadExpanded:
def _load_expanded(select: sa.Select[tuple[EModel]]):
return _load(select).options(
selectinload(EModel.assets),
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.species),
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.strain),
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.brain_region),
selectinload(EModel.ion_channel_models).selectinload(IonChannelModel.assets),
raiseload("*"),
)

return router_read_one(
id_=id_,
db=db,
db_model_class=EModel,
authorized_project_id=user_context.project_id,
response_schema_class=EModelReadExpanded,
apply_operations=_load_expanded,
apply_operations=_load,
)


Expand Down Expand Up @@ -99,10 +95,12 @@ def read_many(
with_search: SearchDep,
facets: FacetsDep,
in_brain_region: InBrainRegionDep,
) -> ListResponse[EModelRead]:
) -> ListResponse[EModelReadExpanded]:
morphology_alias = aliased(ReconstructionMorphology, flat=True)
ion_channel_model_alias = aliased(IonChannelModel, flat=True)
aliases: Aliases = {
ReconstructionMorphology: morphology_alias,
IonChannelModel: ion_channel_model_alias,
}

name_to_facet_query_params: dict[str, FacetQueryParams] = {
Expand Down Expand Up @@ -132,6 +130,11 @@ def filter_query_operations(q: sa.Select):
.outerjoin(MTypeClass, MTypeClass.id == MTypeClassification.mtype_class_id)
.outerjoin(ETypeClassification, EModel.id == ETypeClassification.entity_id)
.outerjoin(ETypeClass, ETypeClass.id == ETypeClassification.etype_class_id)
.outerjoin(IonChannelModelToEModel, EModel.id == IonChannelModelToEModel.emodel_id)
.outerjoin(
ion_channel_model_alias,
ion_channel_model_alias.id == IonChannelModelToEModel.ion_channel_model_id,
)
)

return router_read_many(
Expand All @@ -145,7 +148,7 @@ def filter_query_operations(q: sa.Select):
apply_filter_query_operations=filter_query_operations,
apply_data_query_operations=_load,
pagination_request=pagination_request,
response_schema_class=EModelRead,
response_schema_class=EModelReadExpanded,
name_to_facet_query_params=name_to_facet_query_params,
filter_model=emodel_filter,
)
2 changes: 1 addition & 1 deletion tests/test_emodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_query_emodel(client: TestClient, create_emodel_ids: CreateIds):
assert len(data) == 11

assert "assets" in data[0]
assert "ion_channel_models" not in data[0]
assert "ion_channel_models" in data[0]


def test_emodels_sorted(client: TestClient, create_emodel_ids: CreateIds):
Expand Down