rDrama/files/classes/follows.py
justcool393 e040ed6708 Upgrade to SQLAlchemy 2.0
This has exposed an interesting amount of bugs and stopped throwing type errors every 5 seconds

It's worth noting that not all models are fully typed, that is, we
have `Mapped[Any]` in some places where a narrower type would be nice.

Upgrading to SQLA2 we don't *need* this, but it is helpful and
makes error checking reliable.
2023-08-09 02:27:55 -05:00

21 lines
741 B
Python

from sqlalchemy import *
from sqlalchemy.orm import Mapped, mapped_column, relationship
from files.classes.base import CreatedDateTimeBase
class Follow(CreatedDateTimeBase):
__tablename__ = "follows"
target_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), primary_key=True)
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), primary_key=True)
Index('follow_user_id_index', user_id)
user = relationship("User", uselist=False, primaryjoin="User.id==Follow.user_id", viewonly=True)
target = relationship("User", primaryjoin="User.id==Follow.target_id", viewonly=True)
def __repr__(self):
return (
f"<{self.__class__.__name__}("
f"target_id={self.target_id}, user_id={self.user_id})>"
)