简体   繁体   English

如何在具有多个PK的集合中使用'via'属性?

[英]How to use the 'via' attribute in a collection with more than one PK?

How to use the 'via' attribute in a collection with more than one PK? 如何在具有多个PK的集合中使用'via'属性? Below is an example of a hasMany datamodel. 以下是hasMany数据模型的示例。

The Model Definition. 模型定义。

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'
        }
    }
});

The Collection Definition with the two 'via' attributes. 具有两个“ 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' // ?????????
        }
    }
});

Do not use via like this, because value of via will be overwritten. 不要这样使用via ,因为via值将被覆盖。 So in your case will be like that 所以你的情况就是这样

from_device: {
   model: 'device'
   //via: 'name', <-- omitted
   via: 'uuid'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM