Skip to content

Commit

Permalink
Don't Inherit from Associable in File but in models which derive
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrillkuettel committed Jul 4, 2024
1 parent 14993d5 commit 8d52b58
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/privatim/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class YourModel(Base, Commentable):
model = YourModel(name='stuff')
model.comments.append(Comment('Interesting sqlalchemy design pattern'))
"""
"""

__tablename__ = 'comments'

Expand Down
3 changes: 2 additions & 1 deletion src/privatim/models/commentable.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from privatim.models.comment import Comment
from privatim.orm.associable import associated
from sqlalchemy.orm import Mapped


class Commentable:
""" Use this in your model to attach a list[Comment] """

comments = associated(
comments: 'Mapped[list[Comment]]' = associated(
Comment, 'comments', 'one-to-many'
)
5 changes: 3 additions & 2 deletions src/privatim/models/file.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from sqlalchemy.orm import Mapped, mapped_column, deferred
from privatim.orm.abstract import AbstractFile
from privatim.orm.associable import Associable
from privatim.orm.meta import UUIDStrPK
from sqlalchemy import Text, ForeignKey, Integer


class GeneralFile(AbstractFile):
class GeneralFile(AbstractFile, Associable):
"""A general file (image, document, pdf, etc), referenced in the database.
A thin wrapper around the `File` from sqlalchemy-file so that we can easily
Expand All @@ -19,7 +20,7 @@ class GeneralFile(AbstractFile):
}


class SearchableFile(AbstractFile):
class SearchableFile(AbstractFile, Associable):
"""
A file with the intention of being searchable. Should to be used with
SearchableAssociatedFiles.
Expand Down
3 changes: 1 addition & 2 deletions src/privatim/orm/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy_file import File

from privatim.orm.associable import Associable
from privatim.orm.meta import UUIDStrPK, AttachedFile
from privatim.orm import Base

Expand All @@ -14,7 +13,7 @@
from privatim.types import ACL


class AbstractFile(Base, Associable):
class AbstractFile(Base):
__abstract__ = True

id: Mapped[UUIDStrPK] = mapped_column(primary_key=True)
Expand Down

0 comments on commit 8d52b58

Please sign in to comment.