【发布时间】:2016-10-17 10:25:31
【问题描述】:
如何在具有多个 PK 的集合中使用 'via' 属性? 下面是一个 hasMany 数据模型的示例。
模型定义。
Persistence.prototype.collections.Device = Waterline.Collection.extend({
identity: 'device',
connection: 'default',
attributes: {
name: {
type: 'string',
required: true,
primaryKey: true
},
uuid:{
type: 'string',
required: true,
primaryKey: true
},
dataItems: {
collection: 'dataitem',
via: 'id'
}
}
});
具有两个“via”属性的集合定义。
Persistence.prototype.collections.DataItem = Waterline.Collection.extend({
identity: 'dataitem',
connection: 'default',
attributes: {
id: {
type: 'string',
unique: true,
primaryKey: true
},
category: 'string',
type: 'string',
from_device: {
model: 'device'
via: 'name', // ??????
via: 'uuid' // ?????????
}
}
});
【问题讨论】:
标签: javascript sails.js waterline sails-postgresql