diff --git a/mwdb/model/object.py b/mwdb/model/object.py index c5b4e4c3..256dfa74 100644 --- a/mwdb/model/object.py +++ b/mwdb/model/object.py @@ -58,12 +58,14 @@ class Object(db.Model): share_3rd_party = db.Column(db.Boolean, nullable=False) upload_count = column_property( - select([func.count(distinct(ObjectPermission.related_user_id))]).where( + select([func.count(distinct(ObjectPermission.related_user_id))]) + .where( and_( ObjectPermission.object_id == id, ObjectPermission.reason_type == AccessType.ADDED, ) - ), + ) + .scalar_subquery(), deferred=True, ) @@ -105,7 +107,7 @@ class Object(db.Model): "User", secondary="comment", back_populates="commented_objects", - passive_deletes=True, + viewonly=True, ) shares = db.relationship( diff --git a/mwdb/model/user.py b/mwdb/model/user.py index 9c697d06..1bdf30c8 100644 --- a/mwdb/model/user.py +++ b/mwdb/model/user.py @@ -68,7 +68,7 @@ class User(db.Model): "Object", secondary="comment", back_populates="comment_authors", - passive_deletes=True, + viewonly=True, ) comments = db.relationship(