MCPcopy
hub / github.com/strongloop/loopback / applyCreate

Function applyCreate

lib/persisted-model.js:1552–1579  ·  view source on GitHub ↗
(Model, id, current, data, change, conflicts, options, cb)

Source from the content-addressed store, hash-verified

1550 }
1551
1552 function applyCreate(Model, id, current, data, change, conflicts, options, cb) {
1553 Model.create(data, options, function(createErr) {
1554 if (!createErr) return cb();
1555
1556 // We don't have a reliable way how to detect the situation
1557 // where he model was not create because of a duplicate id
1558 // The workaround is to query the DB to check if the model already exists
1559 Model.findById(id, function(findErr, inst) {
1560 if (findErr || !inst) {
1561 // There isn't any instance with the same id, thus there isn't
1562 // any conflict and we just report back the original error.
1563 return cb(createErr);
1564 }
1565
1566 return conflict();
1567 });
1568 });
1569
1570 function conflict() {
1571 // The instance already exists - report a conflict
1572 debug('Detected non-rectified new instance of %s %j',
1573 Model.modelName, id);
1574 conflicts.push(change);
1575
1576 const Change = Model.getChangeModel();
1577 return Change.rectifyModelChanges(Model.modelName, [id], cb);
1578 }
1579 }
1580
1581 function applyDelete(Model, id, current, change, conflicts, options, cb) {
1582 if (!current) {

Callers 1

persisted-model.jsFile · 0.85

Calls 1

conflictFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…