This commit is contained in:
2026-01-07 10:58:25 +03:00
parent 2d4ee6c77b
commit 7cc194abe5
4 changed files with 47 additions and 2 deletions
@@ -41,7 +41,7 @@ class TestDAO:
async def get_all(self) -> list[DomainTest]:
result = await self.session.execute(
select(Test).order_by(Test.created_at.desc())
select(Test).order_by(Test.is_active.desc(), Test.created_at.desc())
)
models = list(result.scalars().all())
return [TestDTO(model).to_domain() for model in models]
+6 -1
View File
@@ -63,6 +63,11 @@ class Test(Base):
cascade="all, delete-orphan",
order_by="Question.position"
)
test_attempts: Mapped[list["TestAttempt"]] = relationship(
back_populates="test",
cascade="all, delete-orphan",
)
@final
@@ -110,7 +115,7 @@ class TestAttempt(Base):
is_passed: Mapped[bool] = mapped_column(default=False)
user: Mapped["User"] = relationship()
test: Mapped["Test"] = relationship()
test: Mapped["Test"] = relationship(back_populates="test_attempts")
answers: Mapped[list["UserAnswer"]] = relationship(
back_populates="attempt",
cascade="all, delete-orphan"