mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 21:15:13 +00:00
update where query (#74)
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user