【发布时间】:2015-01-28 00:31:06
【问题描述】:
我是 Sails.js 和 OrientDB 的新手。我试图弄清楚如何使用sails-orientDB 适配器创建具有多个边的模型。
我有一个存储基本车辆信息和车辆颜色的车型:
module.exports = {
schema: true,
tableName: 'Vehicle',
attributes: {
id: {
type: 'string',
primaryKey: true,
columnName: '@rid'
},
make: {
type: 'string',
unique: false,
required: true
},
model: {
type: 'string',
unique: false,
required: true
},
year: {
type: 'int',
int: true,
unique: false,
required: true
},
color: {
collection: 'Vehicle_Color',
via: 'color',
edge: 'vehicleColor'
}
}
};
还有一个车辆颜色模型:
module.exports = {
schema: true,
tableName: 'Vehicle_Color',
attributes: {
id: {
type: 'string',
primaryKey: true,
columnName: '@rid'
},
name: {
type: 'string',
unique: true,
required: true
},
hexCode: {
type: 'string',
hexColor: true
}
}
};
我希望每辆载具能够有多种颜色。例如
- VehicleA -> 红色
- VehicleA -> 蓝色
- VehicleA -> 黄色
文档显示了如何设置一对一关系,但我无法找出正确的方法来进行一对多或多对多。我研究过使用这个适配器:npmjs.com/package/waterline-orientdb,但这看起来否定了使用图形数据库的好处(github.com/appscot/waterline-orientdb/issues/29)。
我可以简单地创建一个边缘模型吗:
module.exports = {
schema: true,
tableName: 'Vehicle_Color',
attributes: {
vehicleID: {
type: 'string',
},
colorID: {
type: 'string',
},
}
};
然后在我的模型中存储这些边的数组?有一个更好的方法吗?提前致谢。
【问题讨论】:
标签: node.js sails.js graph-databases orientdb waterline