From 6a889ca2e7c63870be014a3d2f3822b3f63a751d Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 4 Jun 2018 14:29:00 +0100 Subject: [PATCH] Add references between items. --- sourcing/model.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sourcing/model.py b/sourcing/model.py index 71f5e72..6281185 100644 --- a/sourcing/model.py +++ b/sourcing/model.py @@ -127,9 +127,6 @@ class Reference(Base): subject_id = Column(Integer, ForeignKey('item.id'), primary_key=True) object_id = Column(Integer, ForeignKey('item.id'), primary_key=True) - subject_item = relationship('User', backref='objects') - object_item = relationship('User', backref='subjects') - class Item(TimeStampedModel): __tablename__ = 'item' __versioned__ = {'base_classes': (TimeStampedModel,)} @@ -142,15 +139,14 @@ class Item(TimeStampedModel): filename = Column(Unicode) text = Column(UnicodeText) - subjects = relationship('item', + subjects = relationship('Item', secondary='reference', - # backref='object_item', - primaryjoin=id == Reference.object_id) - objects = relationship('item', + backref='object_item', + foreign_keys=Reference.subject_id) + objects = relationship('Item', secondary='reference', - # backref='subjects_item', - primaryjoin=id == Reference.subject_id) - + backref='subjects_item', + foreign_keys=Reference.object_id) user = relationship('User', backref='items') __mapper_args__ = {