From bdcc89b4038e770e4d9e9b7a59734305f6b4eb5d Mon Sep 17 00:00:00 2001 From: Alexey Bezhan Date: Thu, 9 Nov 2017 14:50:18 +0000 Subject: [PATCH] Add TemplateHistory.redact_personalisation attribute TemplateHistory objects need to be connected to the template's TemplateRedacted record. This requires setting up a new SQLAlchemy relationship to allow accessing redact_personalisation from TemplateHistory instances. We can avoid creating a foreign key in this case by setting up an explicit `primaryjoin` expression. Since TemplateHistory.id is created from Template.id and TemplateRedacted.template_id is already a foreign key to Template.id the foreign key should always be valid even without a DB constraint. --- app/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models.py b/app/models.py index f209dbb13..7b7e012aa 100644 --- a/app/models.py +++ b/app/models.py @@ -645,6 +645,11 @@ class TemplateHistory(db.Model): nullable=False, default=NORMAL) + template_redacted = db.relationship('TemplateRedacted', foreign_keys=[id], + primaryjoin='TemplateRedacted.template_id == TemplateHistory.id') + + redact_personalisation = association_proxy('template_redacted', 'redact_personalisation') + def get_link(self): return url_for( "v2_template.get_template_by_id",