Skip to content

Commit

Permalink
B Activity plugin works with PKs named other than id. closes kvesteri…
Browse files Browse the repository at this point in the history
  • Loading branch information
jstolarski authored and Rico Pundrich committed Apr 16, 2019
1 parent 9421ff3 commit a885bae
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sqlalchemy_continuum/plugins/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@

import sqlalchemy as sa
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.inspection import inspect
from sqlalchemy_utils import JSONType, generic_relationship

from .base import Plugin
Expand Down Expand Up @@ -254,11 +255,13 @@ def _calculate_tx_id(self, obj):
if object_version:
return object_version.transaction_id

version_cls = version_class(obj.__class__)
model = obj.__class__
version_cls = version_class(model)
primary_key = inspect(model).primary_key[0].name
return session.query(
sa.func.max(version_cls.transaction_id)
).filter(
version_cls.id == obj.id
getattr(version_cls, primary_key) == getattr(obj, primary_key)
).scalar()

def calculate_object_tx_id(self):
Expand Down

0 comments on commit a885bae

Please sign in to comment.