You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
…but this triggers the ArrayableNormalizer instead of the ModelNormalizer for nested DTOs, which means:
Custom attributes aren’t resolved
Lazy-loaded relations aren’t handled
Other ModelNormalizer features are lost
Question:
Is there an official way to construct a parent DTO from a model inside fromModeland have nested DTO properties resolved via the ModelNormalizer, without having to manually map every property in the constructor (which gets cumbersome for large DTOs)?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
The docs show that you can create DTOs from magic methods like
fromModel
by manually constructing them:However, if the DTO has nested DTOs, e.g.:
…it’s not possible to call
self::from($song)
insidefromModel
(infinite loop).The only workaround I’ve found is to use the array constructor:
…but this triggers the
ArrayableNormalizer
instead of theModelNormalizer
for nested DTOs, which means:ModelNormalizer
features are lostQuestion:
Is there an official way to construct a parent DTO from a model inside
fromModel
and have nested DTO properties resolved via theModelNormalizer
, without having to manually map every property in the constructor (which gets cumbersome for large DTOs)?Beta Was this translation helpful? Give feedback.
All reactions