簡體   English   中英

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

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

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

不要這樣使用via ,因為via值將被覆蓋。 所以你的情況就是這樣

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM