Adonis 5 - Conditional Serialize null

Hi guys!

I have a question about serializers. I’m just trying AdonisJs making a user model, and I want to hide the user’s email (it will be a REST Api, so I have to hide it because I user the user model as relationship of other models).

Well, with this configuration it works as expected:

@column({serializeAs: null})
  public email: string

The question is: If I want to enable the user to edit his email, how can I retrieve it?

When I try this simple code:

const user = User.query().where('id',params.id)
    .preload('profile')
    .first()

It obviously not return the email. So how can I get it?

Even if I try .select('*') on the model, it’s not returning the email field.

Thanks in advance for your help!

1 Like