Nested object in schema

node v6.17.1
version: 2.0.0
endpointsharetweet
const JSData = require('js-data@3.0.0-rc.8'); const addressSchema = new JSData.Schema({ type: 'object', properties: { uid: { type: 'string' }, tag: { type: ['string', 'null'] }, country: { type: 'object', additionalProperties: true, get () { return { foo: 'bar' }; } } } }); const addressMapper = new JSData.Mapper({ name: 'address', schema: addressSchema }) const address = addressMapper.createRecord({ uid: '1234', tag: 'test' }); console.log(address); console.log(address.toJSON());
const countrySchema = new JSData.Schema({ type: 'object', properties: { code: { type: 'string' } } }); const addressSchema2 = new JSData.Schema({ type: 'object', properties: { uid: { type: 'string' }, tag: { type: ['string', 'null'] }, country: { type: 'object', additionalProperties: countrySchema, get () { return { foo: 'bar' }; } } } }); const addressMapper2 = new JSData.Mapper({ name: 'address', schema: addressSchema }) const address2 = addressMapper.createRecord({ uid: '1234', tag: 'test' }); console.log(address2); console.log(address2.toJSON());
Loading…

no comments

    sign in to comment