couchbaselabs / node-ottoman

Node.js ODM for Couchbase
https://ottomanjs.com/
Apache License 2.0
287 stars 98 forks source link

ArrayType is not handling options correctly #716

Closed gsi-alejandro closed 1 year ago

gsi-alejandro commented 1 year ago

ArrayType options are set to undefined even when you use some options.

Current behavior: Define schema like this:

const userSchema = new Schema({
    test: {default: ()=>[], type: [{type: String, ref: 'Article'}]}
});

Produce:

ArrayType {
  name: 'Article',
  typeName: 'Array',
  options: undefined,
  itemType: ReferenceType {
    name: '',
    typeName: 'Reference',
    options: undefined,
    schema: Schema {
      statics: {},
      methods: {},
      preHooks: {},
      postHooks: {},
      index: {},
      queries: {},
      options: [Object],
      fields: {}
    },
    refModel: 'Article'
  }
}

Notice: options were set to undefined

Correct behavior should be:

ArrayType {
  name: 'Article',
  typeName: 'Array',
  options: {default: ()=>[]},
  itemType: ReferenceType {
    name: '',
    typeName: 'Reference',
    options: undefined,
    schema: Schema {
      statics: {},
      methods: {},
      preHooks: {},
      postHooks: {},
      index: {},
      queries: {},
      options: [Object],
      fields: {}
    },
    refModel: 'Article'
  }
}

Notice: options has the default value set (options: {default: ()=>[]},)