I am new to Sails.js and OrientDB. I am trying to figure out how to create a model that has multiple edges using the sails-orientDB adapter.
I have a vehicle model that stores basic vehicle information and a vehicle color:
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'
}
}
};
And a vehicle Color Model:
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
}
}
};
I want each Vehicle to be able to have multiple colors. For Example
- VehicleA -> Red
- VehicleA -> Blue
- VehicleA -> Yellow
The documentation shows how to set up a one to one relation, but I cant figure out the correct way to do one to many, or many to many. I looked into using this adapter: npmjs.com/package/waterline-orientdb but that looks like it negates the benefits (github.com/appscot/waterline-orientdb/issues/29) of using a graph Database.
Would I simply create an edge model like:
module.exports = {
schema: true,
tableName: 'Vehicle_Color',
attributes: {
vehicleID: {
type: 'string',
},
colorID: {
type: 'string',
},
}
};
And then in my model store an array of those edges? Is there a better way to do this? Thanks in advance.