node-ottoman
node-ottoman copied to clipboard
unexpected `strict` in the ShemaOptions
According to the doc:
- https://ottomanjs.com/guides/schema.html#schema-options
- https://ottomanjs.com/guides/schema.html#strict-mode
The strict option (enabled by default) ensures that values passed to our model constructor that were not specified in our schema do not get saved to the database.
it is supposed to be enabled by default. However, it turns out that when specifying a SchemaOptions that doesn't include the strict property(e.g. new Schema({ name: String, age: Number }, { timestamps: true }), the default becomes false.
It's misleading and not consistent with the doc.
pointing out the related code as follows,
https://github.com/couchbaselabs/node-ottoman/blob/776253abdf8585ddff08e5f462127a97c5f53752/src/schema/schema.ts#L99-L103
thanks @xavierchow
this line will be changed to:
const strict = options?.strict === undefined ? false : options.strict;
Next release will ship this fix.
@gsi-alejandro
this line will be changed to:
const strict = options?.strict === undefined ? false : options.strict;
shouldn't be true as the default?
const strict = options?.strict === undefined ? true : options.strict;
Sorry @xavierchow
I share with you a piece of code with an error, the committed one is correct and will be shipped in the next release.
this commit:

@gsi-alejandro thank you for your explanation; looking forward to the next release!
@gsi-alejandro is this done if so please close this issue
Cc : @thejcfactor