Skip to content
Closed
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
25 changes: 24 additions & 1 deletion app/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,23 @@ def etypes(cls) -> Mapped[list["ETypeClass"]]:
)


class ValidationResultsMixin:
@declared_attr
@classmethod
def validation_results(cls) -> Mapped[list["ValidationResult"]]:
if not issubclass(cls, Entity):
msg = f"{cls} should be an Entity"
raise TypeError(msg)

return relationship(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should pass uselist=True

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done in latest commit

"ValidationResult",
primaryjoin=f"foreign(ValidationResult.validated_entity_id) == {cls.__name__}.id",
foreign_keys="[ValidationResult.validated_entity_id]",
cascade="all, delete",
uselist=True,
)


class DataMaturityAnnotationBody(AnnotationBody):
__tablename__ = AnnotationBodyType.datamaturity_annotation_body.value
id: Mapped[uuid.UUID] = mapped_column(ForeignKey("annotation_body.id"), primary_key=True)
Expand Down Expand Up @@ -471,7 +488,13 @@ class Mesh(LocationMixin, NameDescriptionVectorMixin, Entity):


class MEModel(
MTypesMixin, ETypesMixin, SpeciesMixin, LocationMixin, NameDescriptionVectorMixin, Entity
ValidationResultsMixin,
MTypesMixin,
ETypesMixin,
SpeciesMixin,
LocationMixin,
NameDescriptionVectorMixin,
Entity,
):
__tablename__ = EntityType.memodel.value
id: Mapped[uuid.UUID] = mapped_column(ForeignKey("entity.id"), primary_key=True)
Expand Down
2 changes: 2 additions & 0 deletions app/schemas/me_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from app.schemas.contribution import ContributionReadWithoutEntity
from app.schemas.emodel import EModelRead
from app.schemas.morphology import ReconstructionMorphologyRead
from app.schemas.validation import ValidationResultRead


class MEModelBase(BaseModel):
Expand Down Expand Up @@ -59,3 +60,4 @@ class MEModelRead(
etypes: list[ETypeClassRead] | None
morphology: ReconstructionMorphologyRead
emodel: EModelRead
validation_results: list[ValidationResultRead] = []
1 change: 1 addition & 0 deletions app/service/memodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def _load(select: Select):
joinedload(MEModel.etypes),
joinedload(MEModel.created_by),
joinedload(MEModel.updated_by),
selectinload(MEModel.validation_results),
raiseload("*"),
)

Expand Down