Replies: 1 comment
-
Hi @wivaku :)
you could used casts
you could simply used the magic method from and add them together to the same property 👍 I hope it is help, I'm encourage you to read the documentation |
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
-
What is the best practice to prepare data before creating a nested Data object?
(related to #414)
I load array data from an external API.
Just as an example, this could be the data I get from that API:
The DTO knows the
PostData
has aUserData
, and a collection ofCommentData
which consists ofUserData
(andreplies
, which have the same structure asCommentData
), andlikes
which is a collection ofUserData
. Again, just a (simplified) example.If the json is in the correct format all I have to do is:
But in my case I need to prepare that raw data before creating my object.
E.g. convert durations / timestamps from milliseconds to seconds, or compute fields like name from first+last name.
I prefer that each of the DTO's has the knowledge about preparing that particular DTO (as opposed to preparing the data before handing it over to the
PostData::from(...)
.E.g. every time a
UserData
object is encountered (inpost
,comments
orreplies
) get the name from first+last name,and every time a
CommentData
is encountered (in comment or reply) converts the timestamp from milliseconds to seconds.But when I create them from a model, then none of these preparations are needed (or even: possible).
What is recommended?
Beta Was this translation helpful? Give feedback.
All reactions