update where query (#74)

This commit is contained in:
dylan
2023-05-25 18:43:31 +08:00
committed by GitHub
parent d8b19705ab
commit 4868cb142b
+4 -4
View File
@@ -104,16 +104,16 @@ class CRUDUser(CRUDBase[User, CreateUser, UpdateUser]):
async def get_user_with_relation(
self, db: AsyncSession, *, user_id: int = None, username: str = None
) -> User | None:
where = 'condition'
where = []
if user_id:
where = 'self.model.id == user_id'
where.append(self.model.id == user_id)
if username:
where = 'self.model.username == username'
where.append(self.model.username == username)
user = await db.execute(
select(self.model)
.where(eval(where))
.options(selectinload(self.model.dept))
.options(selectinload(self.model.roles).joinedload(Role.menus))
.where(*where)
)
return user.scalars().first()