Given models A and B (where A has many B), what is the most performant way to accomplish the following with Loopback?
* Create A
* Create B
* Add B to A
$ lb init
$ lb model A
...
$ lb model B
...
$ lb relation
# configure A to have many B
common/models/A.js
'use strict';
module.exports = function(A) {
A.createAWithB = function({ a, b }, cb) {
const { B } = A.app.models;
A.create(a, (err, a) => {
if(err) return cb('Error creating A in createAWithB');
B.create(Object.assign({}, b, { aId: a.id }), (err, b) => {
if(err) return cb('Error creating B in createAWithB');
cb(null, a);
});
});
};
A.remoteMethod(
'createAWithB', {
http: {
path: '/createAWithB',
verb: 'post'
},
accepts: {
arg: 'vm',
type: 'Object',
http: {
source: 'body'
}
},
returns: {
arg: 'a',
type: 'Object'
}
}
);
};