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' // ?????????
}
}
});
私はあなたのことを理解しましたが、質問は残っています。両方のPKを使用するには?それにもかかわらず、ありがとうございました。 – mluis
これは不可能ではないかと思います。 DBでは、1つのPKのみになります。他のユニークなフィールドは通常のフィールドと同じように扱われます – SkyQ
プライマリキーとして2つのフィールドを実際に作成したい場合は、DBの構造を再構築し、最初のプライマリキーとなる2つのテーブルを作成し、 – SkyQ