I'm just using loopback last few weeks. I would like to insert in synchronous process. When the first data is inserted into table, then the id will be inserted into the other table.
i've got an error response like this :
{"error":{"status":500,"message":"An unknown error occurred"}}
my code :
accountModel.create(customerObj.Account, function(error,resp) {
if(error){
cb(false, {"message" : "Something Wrong", "err" : error});
} else {
var account_id = resp.result.id;
customerObj.Contact.accountId = account_id;
customerObj.AccountBank.accountId = account_id;
if(customerObj.Contact){
contactModel.create(customerObj.Contact, function(err, response) {
if(err){
feedbackArr.push({"Contact" : 'error', "err" : err});
} else {
feedbackArr.push({"Contact" : 'success', "response" : response});
if(customerObj.AccountBank){
bankModel.create(customerObj.AccountBank, function(e,r) {
if(e){
feedbackArr.push({"AccountBank" : 'error', "err" : e});
} else {
feedbackArr.push({"AccountBank" : 'success', "response" : r});
cb(true,feedbackArr);
}
})
}
}
});
}
}
})
All of models base on PersistedModel. Any ideas ?
via Ucok Haleluya
No comments:
Post a Comment