You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// the properties passed to Model.extend(name, properties, options)
72
+
"properties": {
73
+
"id": {"id":true},
74
+
"name":"String",
75
+
"zip":"Number",
76
+
"address":"String"
77
+
}
78
+
},
79
+
"inventory": {
80
+
"dataSource":"my-db"
81
+
"options": {
82
+
"plural":"inventory"
83
+
},
84
+
"properties": {
85
+
"id": {
86
+
"type":"String",
87
+
"required":true,
88
+
"id":true,
89
+
"length":20
90
+
},
91
+
"available": {
92
+
"type":"Number",
93
+
"required":false
94
+
},
95
+
"total": {
96
+
"type":"Number",
97
+
"required":false
98
+
}
99
+
}
100
+
}
101
+
}
102
+
```
32
103
33
-
app.model(Color);
34
-
app.use(loopback.rest());
104
+
**Model Definition Properties**
105
+
106
+
-`dataSource` - **required** - a string containing the name of the data source definition to attach the `Model` to
107
+
-`options` - _optional_ - an object containing `Model` options
108
+
-`properties`_optional_ - an object defining the `Model` properties in [LoopBack Definition Language](http://docs.strongloop.com/loopback-datasource-juggler/#loopback-definition-language)
109
+
110
+
**DataSource Definition Properties**
111
+
112
+
-`connector` - **required** - the name of the [connector](#working-with-data-sources-and-connectors)
113
+
114
+
#### app.model(name, definition)
115
+
116
+
Define a `Model` and export it for use by remote clients.
117
+
118
+
```js
119
+
// declare a DataSource
120
+
app.boot({
121
+
dataSources: {
122
+
db: {
123
+
connector:'mongodb',
124
+
url:'mongodb://localhost:27015/my-database-name'
125
+
}
126
+
}
127
+
});
128
+
129
+
// describe a model
130
+
var modelDefinition = {dataSource:'db'};
131
+
132
+
// create the model
133
+
var Product =app.model('product', modelDefinition);
0 commit comments