diff options
Diffstat (limited to 'shopdb/_associations.py')
-rw-r--r-- | shopdb/_associations.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/shopdb/_associations.py b/shopdb/_associations.py new file mode 100644 index 0000000..e0e25bf --- /dev/null +++ b/shopdb/_associations.py @@ -0,0 +1,24 @@ +from sqlalchemy import Column, Integer, String, Table +from sqlalchemy.orm import relationship +from sqlalchemy import ForeignKey +from ._base import Base +from ._customer import Customer +from ._group import Group +from ._job import Job + + +customer_group = Table('customer_group', Base.metadata, + Column('customer_id', Integer, ForeignKey('customers.id')), + Column('group_id', Integer, ForeignKey('groups.id')) +) +Customer.groups = relationship("Group", secondary=customer_group, back_populates="members") +Group.members = relationship("Customer", secondary=customer_group, back_populates="groups") + + + +customer_job = Table('customer_job', Base.metadata, + Column('customer_id', Integer, ForeignKey('customers.id')), + Column('job_id', Integer, ForeignKey('jobs.id')) +) +Customer.jobs = relationship("Job", secondary=customer_job, back_populates="customers") +Job.customers = relationship("Customer", secondary=customer_job, back_populates="jobs") |