Skip to content

Can SerializeAs be a function? #3440

Answered by thetutlage
LeCoupa asked this question in Help
Discussion options

You must be logged in to vote

You can define your own serializeAttributes function on the model to customize the serialization behavior.

export default class User extends BaseModel {
  public serializeAttributes() {
    // your serialization logic
  }
}

Here is the default implementation https://github.com/adonisjs/lucid/blob/develop/src/Orm/BaseModel/index.ts#L1797

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by LeCoupa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants