loopback-datasource-juggler/examples/nesting-schema.js

45 lines
1002 B
JavaScript
Raw Normal View History

2016-04-01 22:25:16 +00:00
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: loopback-datasource-juggler
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
2016-08-22 19:55:22 +00:00
'use strict';
2018-12-07 16:13:48 +00:00
const ModelBuilder = require('../../loopback-datasource-juggler').ModelBuilder;
const modelBuilder = new ModelBuilder();
2013-07-11 21:24:47 +00:00
// simplier way to describe model
2018-12-07 16:13:48 +00:00
const User = modelBuilder.define('User', {
2014-01-24 17:09:53 +00:00
name: String,
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: Number,
address: {
street: String,
city: String,
state: String,
zipCode: String,
2016-04-01 11:48:17 +00:00
country: String,
2014-01-24 17:09:53 +00:00
},
emails: [
{
label: String,
2016-04-01 11:48:17 +00:00
email: String,
},
2014-01-24 17:09:53 +00:00
],
2016-04-01 11:48:17 +00:00
friends: [String],
2013-07-11 21:24:47 +00:00
});
2018-12-07 16:13:48 +00:00
const user = new User({
2016-04-01 13:23:42 +00:00
name: 'Joe',
age: 20,
2016-08-19 17:46:59 +00:00
address: {street: '123 Main St', 'city': 'San Jose', state: 'CA'},
2014-01-24 17:09:53 +00:00
emails: [
2016-08-19 17:46:59 +00:00
{label: 'work', email: 'xyz@sample.com'},
2014-01-24 17:09:53 +00:00
],
2016-04-01 13:23:42 +00:00
friends: ['John', 'Mary'],
});
2014-02-14 07:42:21 +00:00
console.log(user);
2013-07-12 19:36:14 +00:00
console.log(user.toObject());