From e2dc00b469ccda22876fd86e8f73b11b51c03194 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 20 Aug 2020 14:26:46 -0500 Subject: [PATCH] Add model for `SuperDepartment` --- corepos/db/office_op/model.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/corepos/db/office_op/model.py b/corepos/db/office_op/model.py index 5b494c7..330e8d1 100644 --- a/corepos/db/office_op/model.py +++ b/corepos/db/office_op/model.py @@ -74,6 +74,38 @@ class Parameter(Base): return "{}-{} {}".format(self.store_id, self.lane_id, self.param_key) +class SuperDepartment(Base): + """ + Represents a "super" (parent/child) department mapping. + """ + __tablename__ = 'superdepts' + __table_args__ = ( + sa.ForeignKeyConstraint(['superID'], ['departments.dept_no']), + sa.ForeignKeyConstraint(['dept_ID'], ['departments.dept_no']), + ) + + parent_id = sa.Column('superID', sa.Integer(), primary_key=True, autoincrement=False, nullable=False) + parent = orm.relationship( + 'Department', + foreign_keys=[parent_id], + doc=""" + Reference to the parent department for this mapping. + """, + backref=orm.backref('_super_children')) + + child_id = sa.Column('dept_ID', sa.Integer(), primary_key=True, autoincrement=False, nullable=False) + child = orm.relationship( + 'Department', + foreign_keys=[child_id], + doc=""" + Reference to the child department for this mapping. + """, + backref=orm.backref('_super_parent', uselist=False)) + + def __str__(self): + return "{} / {}".format(self.parent, self.child) + + class Department(Base): """ Represents a department within the organization.