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

Function saveInstance

lib/Instance.js:103–136  ·  view source on GitHub ↗
(saveOptions, cb)

Source from the content-addressed store, hash-verified

101 }
102 };
103 var saveInstance = function (saveOptions, cb) {
104 // what this condition means:
105 // - If the instance is in state mode
106 // - AND it's not an association that is asking it to save
107 // -> return has already saved
108 if (instance_saving && saveOptions.saveAssociations !== false) {
109 return cb(null, instance);
110 }
111 instance_saving = true;
112
113 handleValidations(function (err) {
114 if (err) {
115 return saveError(cb, err);
116 }
117
118 if (opts.is_new) {
119 waitHooks([ "beforeCreate", "beforeSave" ], function (err) {
120 if (err) {
121 return saveError(cb, err);
122 }
123
124 return saveNew(saveOptions, getInstanceData(), cb);
125 });
126 } else {
127 waitHooks([ "beforeSave" ], function (err) {
128 if (err) {
129 return saveError(cb, err);
130 }
131
132 return savePersisted(saveOptions, getInstanceData(), cb);
133 });
134 }
135 });
136 };
137 var runAfterSaveActions = function (cb, create, err) {
138 instance_saving = false;
139

Callers 1

InstanceFunction · 0.85

Calls 7

cbFunction · 0.85
handleValidationsFunction · 0.85
saveErrorFunction · 0.85
waitHooksFunction · 0.85
saveNewFunction · 0.85
getInstanceDataFunction · 0.85
savePersistedFunction · 0.85

Tested by

no test coverage detected