add actual_template relationship to notification

also renamed the function to make it apparent that it'll join and grab personalisation
This commit is contained in:
Leo Hemsted
2016-08-09 13:07:48 +01:00
parent c820938ced
commit 46c0728b12
6 changed files with 43 additions and 22 deletions

View File

@@ -5,7 +5,8 @@ from sqlalchemy.dialects.postgresql import (
UUID,
JSON
)
from sqlalchemy import UniqueConstraint, text
from sqlalchemy import UniqueConstraint, text, ForeignKeyConstraint, and_
from sqlalchemy.orm import foreign, remote
from app.encryption import (
hashpw,
@@ -447,6 +448,14 @@ class Notification(db.Model):
reference = db.Column(db.String, nullable=True, index=True)
_personalisation = db.Column(db.String, nullable=True)
# __table_args__ = (
# ForeignKeyConstraint(['template_id', 'template_version'], ['template_history.id', 'template_history.version']),
# )
actual_template = db.relationship('TemplateHistory', primaryjoin=and_(
foreign(template_id) == remote(TemplateHistory.id),
foreign(template_version) == remote(TemplateHistory.version)
))
@property
def personalisation(self):
if self._personalisation: