From 5a3ede3837cd7cef869f52a3e55325d00a85150d Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Fri, 7 Jul 2023 17:46:18 +0800 Subject: [PATCH] Fix the menu query children exception (#171) --- backend/app/crud/crud_menu.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/app/crud/crud_menu.py b/backend/app/crud/crud_menu.py index cb9b780e..704a9db3 100644 --- a/backend/app/crud/crud_menu.py +++ b/backend/app/crud/crud_menu.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- from sqlalchemy import select, asc, and_ +from sqlalchemy.orm import selectinload from backend.app.crud.base import CRUDBase from backend.app.models import Menu @@ -49,7 +50,9 @@ class CRUDMenu(CRUDBase[Menu, CreateMenu, UpdateMenu]): return await self.delete_(db, menu_id) async def get_children(self, db, menu_id: int) -> list[Menu]: - result = await db.execute(select(self.model).where(self.model.id == menu_id)) + result = await db.execute( + select(self.model).options(selectinload(self.model.children)).where(self.model.id == menu_id) + ) menu = result.scalars().first() return menu.children