howto ? SQLAlchemyDTO add custom DTOField #440
this code is not working :( |
Answered by
provinzkraut
Apr 12, 2025
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. |
0 replies
Answer selected by
dilkhushvakhabov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 aDTODataobject here, having all the fields of the DTO forOrderModel".and this means "Create a DTO for
OrderModeland include itsamountanduser_idsfields". ButOrderModeldoes not have auser_idsfield.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.