feat: deal attributes with select and options
This commit is contained in:
@ -31,29 +31,24 @@ class AttributeRepository(
|
||||
return (
|
||||
stmt.options(joinedload(Attribute.type))
|
||||
.where(Attribute.is_deleted.is_(False))
|
||||
.order_by(Attribute.id)
|
||||
.order_by(Attribute.is_built_in.desc(), Attribute.id)
|
||||
)
|
||||
|
||||
def _process_get_by_id_stmt(self, stmt: Select) -> Select:
|
||||
return stmt.options(joinedload(Attribute.type))
|
||||
|
||||
async def _get_attribute_type_by_id(self, type_id: int) -> AttributeType:
|
||||
stmt = select(AttributeType).where(AttributeType.id == type_id)
|
||||
result = (await self.session.execute(stmt)).one_or_none()
|
||||
if result is None:
|
||||
raise ObjectNotFoundException("Тип аттрибута не найден")
|
||||
return result[0]
|
||||
|
||||
async def update(self, attr: Attribute, data: UpdateAttributeSchema) -> Attribute:
|
||||
if data.type:
|
||||
data.type = await self._get_attribute_type_by_id(data.type.id)
|
||||
return await self._apply_update_data_to_model(attr, data, True)
|
||||
return await self._apply_update_data_to_model(
|
||||
attr, data, with_commit=True, set_if_value_is_not_none=False
|
||||
)
|
||||
|
||||
async def _before_delete(self, attribute: Attribute) -> None:
|
||||
if attribute.is_built_in:
|
||||
raise ForbiddenException("Нельзя менять встроенный атрибут")
|
||||
|
||||
async def _get_all_attributes_for_deal(self, project_id) -> list[tuple[Attribute, int]]:
|
||||
async def _get_all_attributes_for_deal(
|
||||
self, project_id
|
||||
) -> list[tuple[Attribute, int]]:
|
||||
stmt = (
|
||||
select(Attribute, Module.id)
|
||||
.join(Attribute.modules)
|
||||
@ -148,9 +143,8 @@ class AttributeRepository(
|
||||
AttributeLabel.module_id == module_id,
|
||||
),
|
||||
)
|
||||
.where(
|
||||
Attribute.is_deleted.is_(False),
|
||||
)
|
||||
.where(Attribute.is_deleted.is_(False))
|
||||
.options(joinedload(Attribute.select))
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.all())
|
||||
|
||||
Reference in New Issue
Block a user