from sqlalchemy import ForeignKey, Integer from sqlalchemy.orm import Mapped, mapped_column, relationship from fooder.domain.base import Base, AggregateMacrosMixin, CommonMixin from fooder.domain.entry import Entry class Meal(Base, CommonMixin, AggregateMacrosMixin): """Meal.""" name: Mapped[str] order: Mapped[int] diary_id: Mapped[int] = mapped_column(Integer, ForeignKey("diary.id"), index=True) entries: Mapped[list[Entry]] = relationship( lazy="selectin", order_by=Entry.last_changed, cascade="all, delete-orphan", back_populates="meal", )