mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-23 18:13:54 +03:00
28 lines
931 B
Python
28 lines
931 B
Python
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func
|
|
from sqlalchemy.orm import backref, relationship
|
|
|
|
from database import Base
|
|
|
|
|
|
class Department(Base):
|
|
__tablename__ = 'department'
|
|
id = Column(Integer, primary_key=True)
|
|
name = Column(String)
|
|
|
|
|
|
class Employee(Base):
|
|
__tablename__ = 'employee'
|
|
id = Column(Integer, primary_key=True)
|
|
name = Column(String)
|
|
# Use default=func.now() to set the default hiring time
|
|
# of an Employee to be the current time when an
|
|
# Employee record was created
|
|
hired_on = Column(DateTime, default=func.now())
|
|
department_id = Column(Integer, ForeignKey('department.id'))
|
|
# Use cascade='delete,all' to propagate the deletion of a Department onto its Employees
|
|
department = relationship(
|
|
Department,
|
|
backref=backref('employees',
|
|
uselist=True,
|
|
cascade='delete,all'))
|