0

如何在具有多个 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' // ?????????
        }
    }
});
4

1 回答 1

0

不要这样使用via,因为 的值via会被覆盖。所以在你的情况下会是这样

from_device: {
   model: 'device'
   //via: 'name', <-- omitted
   via: 'uuid'
}
于 2016-10-17T14:30:35.127 回答