Replies: 1 comment 5 replies
-
Yeah I think @sebastiandedeyne also already had this problem. The thing is, right now we don't make a distinction between transforming for database or response. I suggest we'll keep the transformation logic as is. This keeps the typescript definitions being generated correctly. Also most of the times within your controllers you do this:
We actually have no idea what's happening here, is it a controller or a value being transformed to be stored somewhere? That being said, in the case of storing a data object within a database, we'll always have a data cast. So I think we can create a hook, like beforeSavingToDatabase where the transformed array would be passed in so that it can be changed for correctly storing it within the database. What do you think? Always open for suggestions. |
Beta Was this translation helpful? Give feedback.
-
I often encounter situations where I want to have the current behavior for saving a data object to the database, but I want to have a different structure when transforming for the front-end.
My top example is enums. I want to save the backed enum as its int or string value, but I also need it to be workable on the front-end when using Inertia or Hybridly.
The above is an example in my application, where this
PilotAssignmentData
is actually saved as a collection. Another data object has aDataCollectionOf(PilotAssignmentData::class)
property.I'm specifying this because it would be bothersome to have to duplicate a nested data object structure just for front-end usage, and I also can't add properties to
PilotAssignmentData
because they would be saved to the database.What I want on the front-end is to obtain this data:
However, I still want it saved properly in the database:
The
value
andhuman_readable
parts could be returned from something like a transformer that I would make myself. The issue is to be able to:I don't think this is doable right now. I would be willing to implement the feature, but I think this requires a bit of brainstorming. Thoughts @rubenvanassche?
Beta Was this translation helpful? Give feedback.
All reactions