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

Function saveNew

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

Source from the content-addressed store, hash-verified

188 return nextHook();
189 };
190 var saveNew = function (saveOptions, data, cb) {
191 var i, prop;
192
193 var finish = function (err) {
194 runAfterSaveActions(function () {
195 if (err) return cb(err);
196 saveInstanceExtra(cb);
197 }, true);
198 }
199
200 data = Utilities.transformPropertyNames(data, Model.allProperties);
201
202 opts.driver.insert(opts.table, data, opts.keyProperties, function (save_err, info) {
203 if (save_err) {
204 return saveError(cb, save_err);
205 }
206
207 opts.changes.length = 0;
208
209 for (i = 0; i < opts.keyProperties.length; i++) {
210 prop = opts.keyProperties[i];
211 opts.data[prop.name] = info.hasOwnProperty(prop.name) ? info[prop.name] : data[prop.name];
212 }
213 opts.is_new = false;
214 rememberKeys();
215
216 if (!shouldSaveAssocs(saveOptions)) {
217 return finish();
218 }
219
220 return saveAssociations(finish);
221 });
222 };
223 var savePersisted = function (saveOptions, data, cb) {
224 var changes = {}, conditions = {}, i, prop;
225

Callers 1

saveInstanceFunction · 0.85

Calls 5

saveErrorFunction · 0.85
rememberKeysFunction · 0.85
shouldSaveAssocsFunction · 0.85
finishFunction · 0.85
saveAssociationsFunction · 0.85

Tested by

no test coverage detected