The property name ‘type’ used in a in model definition can interfere with the built in schema property type definition:
I’ve created the following test model:
const model = ottoman.model(
'Test', {
foo: 'string',
bar: {type: 'string'},
baz: {type:'string',bip:'string'},
zap: {type: {type:'string',bop:'string'}},
zeb: {type: {type:{type:'string'},bap:'string'}},
type: 'string',
}
)
Which gives the following output when introspecting the schema:
[ SchemaField {
name: 'foo',
type: CoreType(string),
readonly: false,
default: undefined,
validator: undefined },
SchemaField {
name: 'bar',
type: CoreType(string),
readonly: false,
default: undefined,
validator: undefined },
SchemaField {
name: 'baz',
type: CoreType(string),
readonly: false,
default: undefined,
validator: undefined },
SchemaField {
name: 'zap',
type: { type: 'string', bop: 'string' },
readonly: false,
default: undefined,
validator: undefined },
SchemaField {
name: 'zeb',
type: { type: [Object], bap: 'string' },
readonly: false,
default: undefined,
validator: undefined },
SchemaField {
name: 'type',
type: CoreType(string),
readonly: false,
default: undefined,
validator: undefined },
SchemaField {
name: '_id',
type: CoreType(string),
readonly: true,
default: [Function: autogenUuid],
validator: undefined } ]
Note the baz CoreType is a string and not an object with ‘type’ and ‘bip’ properties.
This caught me out as I’m dealing with creating models based on objects from another system that uses the ‘type’ keyword extensively. There is no error or warning that the keyword is reserved and it just converts the coreType to a string which is a little confusing.
Cheers,
Fabrice