|
@@ -359,22 +359,27 @@ schema.defineModel({
|
|
|
|
|
|
|
|
**Примеры**
|
|
**Примеры**
|
|
|
|
|
|
|
|
-Определение моделей связанных через `belongsTo` по идентификатору.
|
|
|
|
|
|
|
+Определение моделей связанных через `belongsTo` и `hasMany`
|
|
|
|
|
|
|
|
```js
|
|
```js
|
|
|
// модель "role"
|
|
// модель "role"
|
|
|
schema.defineModel({
|
|
schema.defineModel({
|
|
|
name: 'role',
|
|
name: 'role',
|
|
|
- datasource: 'myMemory',
|
|
|
|
|
properties: {
|
|
properties: {
|
|
|
name: DataType.STRING,
|
|
name: DataType.STRING,
|
|
|
},
|
|
},
|
|
|
|
|
+ relations: {
|
|
|
|
|
+ users: { // название связи
|
|
|
|
|
+ type: RelationType.HAS_MANY, // целевая модель ссылается на текущую
|
|
|
|
|
+ model: 'user', // название целевой модели
|
|
|
|
|
+ foreignKey: 'roleId', // свойство целевой модели для идентификатора
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// модель "user"
|
|
// модель "user"
|
|
|
schema.defineModel({
|
|
schema.defineModel({
|
|
|
name: 'user',
|
|
name: 'user',
|
|
|
- datasource: 'myMemory',
|
|
|
|
|
properties: {
|
|
properties: {
|
|
|
name: DataType.STRING,
|
|
name: DataType.STRING,
|
|
|
},
|
|
},
|