"Omittable" properties (in contrast to Optional) #984
maxanstey-acquire
started this conversation in
Ideas
Replies: 1 comment
-
Or perhaps even it's possible to simply hook something in that says something like:
to avoid implementing a brand new feature for something relatively similar to Optional properties? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I'd like a way of creating partial DTOs whereby if a property is passed as null (or missing entirely) and its DTO property has an "Ommitable" attribute, then it is not set against the DTO at all. The important distinction here (as I'm sure you already understand) becomes clear when we think about a user DTO:
Here we have a DTO with a nullable $name, $email, and $deletedAt -- however the only column that is actually allowed to be null in the DB is deleted_at; we have no distinction between "missing" values and "null" values.
Now we could use optional properties for this, but I don't love casting it to another class that developers will need to handle manually all over the place. What I'd rather have is a design whereby developers assume their DTO has what they need in it (the calling code should ensure e.g. the service method is passed the correctly hydrated DTO) and an error is thrown should that not happen for any reason.
Here's a simple mockup of the intended behaviour: https://pastebin.com/8zSEkx5m
Below is my attempt at using a pipeline, before I decided I'd ask you before hacking around:
What do you think? I'm more than happy to have a proper chat about this and if you think it's something that'd add value to the library I'd gladly put a PR together.
Thanks
Max
Beta Was this translation helpful? Give feedback.
All reactions