MCPcopy Index your code
hub / github.com/dresende/node-orm2 / savePersisted

Function savePersisted

lib/Instance.js:223–275  ·  view source on GitHub ↗
(saveOptions, data, cb)

Source from the content-addressed store, hash-verified

221 });
222 };
223 var savePersisted = function (saveOptions, data, cb) {
224 var changes = {}, conditions = {}, i, prop;
225
226 var next = function (saved) {
227 var finish = function () {
228 saveInstanceExtra(cb);
229 }
230
231 if(!saved && !shouldSaveAssocs(saveOptions)) {
232 finish();
233 } else {
234 if (!shouldSaveAssocs(saveOptions)) {
235 runAfterSaveActions(function () {
236 finish();
237 }, false);
238 } else {
239 saveAssociations(function (err, assocSaved) {
240 if (saved || assocSaved) {
241 runAfterSaveActions(function () {
242 if (err) return cb(err);
243 finish();
244 }, false, err);
245 } else {
246 finish();
247 }
248 });
249 }
250 }
251 }
252
253 if (opts.changes.length === 0) {
254 next(false);
255 } else {
256 for (i = 0; i < opts.changes.length; i++) {
257 changes[opts.changes[i]] = data[opts.changes[i]];
258 }
259 for (i = 0; i < opts.keyProperties.length; i++) {
260 prop = opts.keyProperties[i];
261 conditions[prop.mapsTo] = opts.originalKeyValues[prop.name];
262 }
263 changes = Utilities.transformPropertyNames(changes, Model.allProperties);
264
265 opts.driver.update(opts.table, changes, conditions, function (err) {
266 if (err) {
267 return saveError(cb, err);
268 }
269 opts.changes.length = 0;
270 rememberKeys();
271
272 next(true);
273 });
274 }
275 };
276 var saveAssociations = function (cb) {
277 var pending = 1, errored = false, i, j;
278 var saveAssociation = function (accessor, instances) {

Callers 1

saveInstanceFunction · 0.85

Calls 3

saveErrorFunction · 0.85
rememberKeysFunction · 0.85
nextFunction · 0.70

Tested by

no test coverage detected