node-ottoman icon indicating copy to clipboard operation
node-ottoman copied to clipboard

unexpected `strict` in the ShemaOptions

Open xavierchow opened this issue 3 years ago • 4 comments

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

xavierchow avatar May 12 '22 06:05 xavierchow

thanks @xavierchow

this line will be changed to:

const strict = options?.strict === undefined ? false : options.strict;

Next release will ship this fix.

gsi-alejandro avatar May 17 '22 15:05 gsi-alejandro

@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;

xavierchow avatar May 18 '22 02:05 xavierchow

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.

image

this commit: image

gsi-alejandro avatar May 18 '22 02:05 gsi-alejandro

@gsi-alejandro thank you for your explanation; looking forward to the next release!

xavierchow avatar May 18 '22 03:05 xavierchow

@gsi-alejandro is this done if so please close this issue

Cc : @thejcfactor

AV25242 avatar Oct 10 '22 20:10 AV25242