// myApp/api/models/meter.js
// A meter may have many operations
module.exports = {
attributes: {
Id: {type: 'string', required: true, unique: true}, // meter_id
name: {type: 'string', required: true},
state: {type: 'number', required: true},
// Add a reference to operations
operations: {
collection: 'operations',
via: 'meter'
}
}
};
// myApp/api/models/operation.js
// A operation may only belong to a single meter
module.exports = {
attributes: {
Id: {type: 'string'}, // operation_id
name: {type: 'string', required: true},
// Add a reference to User
meter: {
model: 'meter'
}
}
};
var meters = await Meters.find(id: 123).populate('operations');
// The meters object would look something like the following
// [{
// id: 123,
// name: 'Foo',
// state: '1',
// meters: [{
// id: 1,
// name: 'mymeter',
// user: 123
// }]
// }]
надеюсь, это поможет вам:)