Skip to content

Consider replacing null values with the schema default during validation #124

@marshall007

Description

@marshall007

I think it would make sense for .validate() to populate defaults for null values.

var Doc = thinky.createModel('docs', {
  id: String,
  price: {
    _type: Number,
    default: 0
  }
}, { enforce_type: 'strict' });

Works as expected when doc.price is undefined:

var doc = new Doc({ id: 'UUID' });
doc.validate(); // doc.price === 0

Doesn't work when doc.price is null:

var doc = new Doc({ id: 'UUID', price: null });
doc.validate(); // throws "Value for [price] must be a number."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions