简体   繁体   中英

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? Below is an example of a hasMany datamodel.

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.

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. So in your case will be like that

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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