Open gwesterman opened 1 month ago
Yes, similar to the @DtoUpdateRequired
annotation there should be an equivalent annotation for the CreateDto. I will add it within the next days.
@DtoCreateRequired
annotation has been added in 1.24.0-beta3.
(I'm waiting for some feedback on other features before releasing the next proper version.)
Thank you for implementing this so quickly!
I can confirm, that @DtoCreateRequired
is working for me, but only in conjunction with @DtoRelationIncludeId
. Is this intended?
Currently, each annotation fulfills a different task: @DtoRelationIncludeId
only makes the ID field visible, which is otherwise hidden by default. @DtoCreateRequired
only turns an optional field to required.
But if I think about it, you are probably right. similar to @DtoCreateOptional
which unhides an omitted field, you would expect that @DtoCreateRequired
unhides the field as well.
What I need to check is, if @DtoCreateOptional
only works for normal fields, but also for relation-related fields making @DtoRelationIncludeId
kind of redundant?
I need to generate a
CreateDTO
that contains a required field for theid
of an optional relation that can be set to null after the entry is created. This would typically happen viaonDelete: SetNull
.My use-case is a chat in which messages require a reference to a user/author on creation, but this reference can be null once the user is deleted, which in turn should not cause the message to be deleted.
In the model below this works well for
Channel
, which is a non-optional reference. ThechannelId
field on theCreateMessageDto
is required. But this is not the case forauthorId
.This is a simplified/partial version of my model:
The generated
CreateMessageDto
looks like this:I've tried different combinations of decorators, but cannot get it to work. Am I missing something?
Could a new decorator, for example
@DtoCreateRequired
help in this case?