Hi,
I’m currently modelling some documents for our system and would like to have some “optional” fields for the model, for example. A user may want to customise aspects of something they are ordering, or may just want to use a template. Is it possible to allow an entire sub-document to be “null” or missing (in Couchbase terms) in an Ottoman Model? If so, what’s the best way to achieve this?
Here’s an example:
const OrderItem = ottoman.model('OrderItem', {
orderId: Order,
templateId: FrameTemplate,
customisation: {
width: 'number',
height: 'number'
}
}, {
index: {
findByOrder: {
by: 'orderId',
type: 'n1ql'
},
findByTemplate: {
by: 'templateId',
type: 'n1ql'
},
findByID: {
by: '_id',
type: 'refdoc'
}
}
});
I would like the “customisation” to be optional, so rather than writing:
{type: 'number', default: 0.0}
for width & height, I could somehow signal that customisation can be empty / null.
The other question, leading on from this, is how do I have “variable” sub-objects in a model. For example, supposing some customisations have a “depth” field, but not everything does. I don’t want to fill in values for every possible opportunity in my model, but do I have to do this to achieve my goal?
Thanks
Glen