2016-10-17 1 views
0

複数のPKを持つコレクションで 'via'属性を使用するにはどうすればよいですか? 以下は、hasManyデータモデルの例です。複数のPKを持つコレクションで 'via'属性を使用するにはどうすればよいですか?

モデル定義。

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

2つの 'via'属性を持つコレクション定義。 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' // ????????? 
     } 
    } 
}); 

答えて

0

は、このようなviaを使用しないでください。あなたの場合はそのようになります

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

私はあなたのことを理解しましたが、質問は残っています。両方のPKを使用するには?それにもかかわらず、ありがとうございました。 – mluis

+0

これは不可能ではないかと思います。 DBでは、1つのPKのみになります。他のユニークなフィールドは通常のフィールドと同じように扱われます – SkyQ

+1

プライマリキーとして2つのフィールドを実際に作成したい場合は、DBの構造を再構築し、最初のプライマリキーとなる2つのテーブルを作成し、 – SkyQ

関連する問題