Source code for app.model.orm.community
from typing import List
import sqlalchemy as sql
from sqlalchemy.orm import (
mapped_column,
relationship,
Mapped,
)
from app.model.orm.orm_base import OrmBase
[docs]
class Community(OrmBase):
"A collection of strains measured in a particular study"
# Note: convert to studyUniqueID or delete
[docs]
communityStrains: Mapped[List['CommunityStrain']] = relationship(
back_populates='community',
cascade='all, delete-orphan',
)
[docs]
strains: Mapped[List['StudyStrain']] = relationship(
secondary='CommunityStrains',
viewonly=True,
)
[docs]
def diff(self, other):
strains = frozenset(self.strains)
other_strains = frozenset(other.strains)
return {
'added': other_strains - strains,
'removed': strains - other_strains,
}