reaction-by-fix3
All checks were successful
Deploy on push / deploy (push) Successful in 47s

This commit is contained in:
Untone 2025-04-26 15:50:20 +03:00
parent 631ad47fe8
commit af7fbd2fc9
2 changed files with 7 additions and 9 deletions

View File

@ -31,7 +31,7 @@ class Draft(Base):
__tablename__ = "draft"
# required
created_at: int = Column(Integer, nullable=False, default=lambda: int(time.time()))
# Переименовываем колонки ID, чтобы избежать конфликта имен с relationship
# Колонки для связей с автором
created_by: int = Column("created_by", ForeignKey("author.id"), nullable=False)
community: int = Column("community", ForeignKey("community.id"), nullable=False, default=1)
@ -51,13 +51,11 @@ class Draft(Base):
# auto
updated_at: int | None = Column(Integer, nullable=True, index=True)
deleted_at: int | None = Column(Integer, nullable=True, index=True)
updated_by: int | None = Column("updated_by", ForeignKey("author.id"), nullable=True)
deleted_by: int | None = Column("deleted_by", ForeignKey("author.id"), nullable=True)
# --- Relationships ---
# Оставляем lazy="select" (по умолчанию) для коллекций, будем загружать их через joinedload в запросах
# Только many-to-many связи через вспомогательные таблицы
authors = relationship(Author, secondary="draft_author", lazy="select")
topics = relationship(Topic, secondary="draft_topic", lazy="select")

View File

@ -74,7 +74,7 @@ async def load_drafts(_, info):
joinedload(Draft.authors)
)
# Фильтруем по ID автора (создатель или соавтор)
.filter(or_(Draft.authors.any(Author.id == author_id), Draft.created_by_id == author_id))
.filter(or_(Draft.authors.any(Author.id == author_id), Draft.created_by == author_id))
.all()
)
@ -133,10 +133,10 @@ async def create_draft(_, info, draft_input):
if "id" in draft_input:
del draft_input["id"]
# Добавляем текущее время создания
# Добавляем текущее время создания и ID автора
draft_input["created_at"] = int(time.time())
author = session.query(Author).filter(Author.id == author_id).first()
draft = Draft(created_by=author, **draft_input)
draft_input["created_by"] = author_id
draft = Draft(**draft_input)
session.add(draft)
session.commit()
return {"draft": draft}
@ -223,7 +223,7 @@ async def update_draft(_, info, draft_id: int, draft_input):
# Set updated timestamp and author
current_time = int(time.time())
draft.updated_at = current_time
draft.updated_by = author_id # Assuming author_id is correctly fetched context
draft.updated_by = author_id # Используем ID напрямую
session.commit()
# Invalidate cache related to this draft if necessary (consider adding)