Skip to content

Commit 92fe1e7

Browse files
authored
Fix the query for the sub department (#557)
1 parent 7b08060 commit 92fe1e7

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

backend/app/admin/crud/crud_dept.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,17 @@ async def get_with_relation(self, db: AsyncSession, dept_id: int) -> list[User]:
100100
user_relation = result.scalars().first()
101101
return user_relation.users
102102

103-
async def get_children(self, db: AsyncSession, dept_id: int) -> list[Dept]:
103+
async def get_children(self, db: AsyncSession, dept_id: int) -> Sequence[Dept]:
104104
"""
105105
获取子部门
106106
107107
:param db:
108108
:param dept_id:
109109
:return:
110110
"""
111-
stmt = select(self.model).options(selectinload(self.model.children)).where(self.model.id == dept_id)
111+
stmt = select(self.model).where(self.model.parent_id == dept_id, self.model.del_flag == 0)
112112
result = await db.execute(stmt)
113-
dept = result.scalars().first()
114-
return dept.children
113+
return result.scalars().all()
115114

116115

117116
dept_dao: CRUDDept = CRUDDept(Dept)

0 commit comments

Comments
 (0)