1
我正在使用Python 2.7.2和SQLAlchemy 0.9.3。 一個部門有很多組。Python服務層
class Department(Base):
id = Column(Integer, primary_key=True)
groups = relationship("Group", backref="department")
...
class Group(Base):
id = Column(Integer, primary_key=True)
department_id = Column(Integer, ForeignKey('departments.id'))
...
哪裏get_groups和add_group方法屬於?在DepartmentService或GroupService中?
class DepartmentService(object):
def get_groups(self, dept_id):
...
def add_group(self, dept_id, group):
...
class GroupService(object):
def get_groups(self, dept_id):
...
def add_group(self, dept_id, group):
...
或者我從DepartmentService調用GroupService?
我必須選擇一個。現在我將放入GroupService並將其注入到DepartmentService中。 是的,backref是驚人的:D – Akash