MCPcopy Create free account
hub / github.com/dresende/node-orm2 / saveInstanceProperty

Function saveInstanceProperty

lib/Instance.js:410–439  ·  view source on GitHub ↗
(key, value)

Source from the content-addressed store, hash-verified

408 });
409 };
410 var saveInstanceProperty = function (key, value) {
411 var changes = {}, conditions = {};
412 changes[key] = value;
413
414 if (Model.properties[key]) {
415 if (opts.driver.propertyToValue) {
416 changes[key] = opts.driver.propertyToValue(changes[key], Model.properties[key]);
417 }
418 }
419
420 for (var i = 0; i < opts.keys.length; i++) {
421 conditions[opts.keys[i]] = opts.data[opts.keys[i]];
422 }
423
424 Hook.wait(instance, opts.hooks.beforeSave, function (err) {
425 if (err) {
426 Hook.trigger(instance, opts.hooks.afterSave, false);
427 emitEvent("save", err, instance);
428 return;
429 }
430
431 opts.driver.update(opts.table, changes, conditions, function (err) {
432 if (!err) {
433 opts.data[key] = value;
434 }
435 Hook.trigger(instance, opts.hooks.afterSave, !err);
436 emitEvent("save", err, instance);
437 });
438 });
439 };
440 var setInstanceProperty = function (key, value) {
441 var prop = Model.allProperties[key] || opts.extra[key];
442

Callers 1

addInstancePropertyFunction · 0.85

Calls 1

emitEventFunction · 0.85

Tested by

no test coverage detected