Well, basically I would like to have something similar to the following in the models.json file:
var UserModel = {
firstName: String,
lastName: String,
address: {
street: String,
city: String,
state: String,
zipCode: String
},
...
}
The value of the address is the definition of the address type, which can be also considered as an anonymous model.
If you intend to reuse the address model, we can define it independently and reference it in the user model. For example:
var AddressModel = {
street: String,
city: String,
state: String,
zipCode: String
};
var Address = ds.define('Address', AddressModel);
var UserModel = {
firstName: String,
lastName: String,
address: 'Address', // or address: Address
...
}
var User = ds.define('User', UserModel);
Check this out:
https://github.com/strongloop/loopback-datasource-juggler/blob/master/examples/nesting-schema.js
Thanks,
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.
StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.
On Jun 11, 2014, at 7:30 AM, haohello [email protected] wrote:
Well, basically I would like to have something similar to the following in the models.json file:
var UserModel = {
firstName: String,
lastName: String,
address: {
street: String,
city: String,
state: String,
zipCode: String
},
...
}
The value of the address is the definition of the address type, which can be also considered as an anonymous model.
If you intend to reuse the address model, we can define it independently and reference it in the user model. For example:
var AddressModel = {
street: String,
city: String,
state: String,
zipCode: String
};var Address = ds.define('Address', AddressModel);
var UserModel = {
firstName: String,
lastName: String,
address: 'Address', // or address: Address
...
}var User = ds.define('User', UserModel);
—
Reply to this email directly or view it on GitHub.
thank, but how can we do this from the json config for the model
"properties": {
"address": {
"type": "Address",
"required": true
}
}
Most helpful comment
thank, but how can we do this from the json config for the model