2

I had assumed that the Sails model schema: true config option worked in two directions; i.e. that it 1. would strip out extra fields not defined in the attributes hash before writing to the database, and 2. strip out any extra fields in the database before serving it back to the application (in cases where the database has extra data that we don't need to get.

It looks like it only does 1, and not 2. Is this correct? If so, is there another more elegant built in way to do 2 rather than overwriting the toJSON() method to only return the fields we want?

leejt489
  • 615
  • 6
  • 13

1 Answers1

3

It is true that schema: true only does 1 i.e. strip out extra fields BEFORE saving to the database.

If you do not want to override toJSON, you could create another instance method to do that.

You could also consider overriding toObject if that suits your use case.

galactocalypse
  • 1,905
  • 1
  • 14
  • 29