howto ? SQLAlchemyDTO add custom DTOField #440
-
this code is not working :( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is not a supported feature. Conceptually, DTOs are not designed to work this way. Examining your code closely:
class OrderCreateDTO(SQLAlchemyDTO[OrderModel]):
config = SQLAlchemyDTOConfig(
include={"amount", "user_ids"},
) and this means "Create a DTO for The simple answer is, that if you want a field on your model, you'll have to put it on your model. DTOs are intended to transform data from one shape to another; They are not intended to model data. |
Beta Was this translation helpful? Give feedback.
This is not a supported feature.
Conceptually, DTOs are not designed to work this way.
Examining your code closely:
data: DTOData[OrderModel]
means "I want aDTOData
object here, having all the fields of the DTO forOrderModel
".and this means "Create a DTO for
OrderModel
and include itsamount
anduser_ids
fields". ButOrderModel
does not have auser_ids
field.The simple answer is, that if you want a field on your model, you'll have to put it on your model. DTOs are intended to transform data from one shape to another; They are not intended to model data.