如何在具有多个 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'
}
}
});
具有两个“通过”属性的集合定义。
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' // ?????????
}
}
});