(Model, id, current, data, change, conflicts, options, cb)
| 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) { |
no test coverage detected
searching dependent graphs…