Reserved keyword 'type' in Ottoman models. Small bug

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

Hey @f.reynolds,

The keyword type is indeed used to determine if you are trying to specify a complex object type or not, which is the reason for this behaviour. Feel free to post a bug to https://github.com/couchbaselabs/node-ottoman/issues to update the documentation (or submit a pull request!). Ottoman.v2 is in the works, and allows you to work around this by manually building your model objects rather than needing to use the ‘lossy’ object structure.

Cheers, Brett

Hi @Brett19,

Thanks for the reply, I’ve filed an issue: https://github.com/couchbaselabs/node-ottoman/issues/167

Cheers,

Fabrice