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

Function removeInstance

lib/Instance.js:376–409  ·  view source on GitHub ↗
(cb)

Source from the content-addressed store, hash-verified

374 });
375 };
376 var removeInstance = function (cb) {
377 if (opts.is_new) {
378 return cb(null);
379 }
380
381 var conditions = {};
382 for (var i = 0; i < opts.keys.length; i++) {
383 conditions[opts.keys[i]] = opts.data[opts.keys[i]];
384 }
385
386 Hook.wait(instance, opts.hooks.beforeRemove, function (err) {
387 if (err) {
388 emitEvent("remove", err, instance);
389 if (typeof cb === "function") {
390 cb(err, instance);
391 }
392 return;
393 }
394
395 emitEvent("beforeRemove", instance);
396
397 opts.driver.remove(opts.table, conditions, function (err, data) {
398 Hook.trigger(instance, opts.hooks.afterRemove, !err);
399
400 emitEvent("remove", err, instance);
401
402 if (typeof cb === "function") {
403 cb(err, instance);
404 }
405
406 instance = undefined;
407 });
408 });
409 };
410 var saveInstanceProperty = function (key, value) {
411 var changes = {}, conditions = {};
412 changes[key] = value;

Callers 1

InstanceFunction · 0.85

Calls 3

cbFunction · 0.85
emitEventFunction · 0.85
removeMethod · 0.65

Tested by

no test coverage detected