Serialize Relationships as null #2041
popovicieduard
started this conversation in
Ideas
Replies: 1 comment 7 replies
-
I agree, that would be useful. Like so: In a controller: public async method({ params }: HttpContextContract) {
const user = User.findOrFail(params.id)
// Business logic
return {
...user.serialize(),
posts: undefined,
postsCount: user.posts.length
}
} Will yield the response: {
"id": 1,
.... rest user props
"posts_count": 5
} |
Beta Was this translation helpful? Give feedback.
7 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.
-
It would be nice to be able to serialize relationships as null since for some use cases, you want to have a computed property of multiple relationships and serialize them as null to hide them from responses, I tried using undefined but they are still showing, this code although works it's throwing a type error:
Beta Was this translation helpful? Give feedback.
All reactions