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

Function autoFetchInstance

lib/Associations/One.js:296–318  ·  view source on GitHub ↗
(Instance, association, opts, cb)

Source from the content-addressed store, hash-verified

294}
295
296function autoFetchInstance(Instance, association, opts, cb) {
297 if (!Instance.saved()) {
298 return cb();
299 }
300
301 if (!opts.hasOwnProperty("autoFetchLimit") || typeof opts.autoFetchLimit === "undefined") {
302 opts.autoFetchLimit = association.autoFetchLimit;
303 }
304
305 if (opts.autoFetchLimit === 0 || (!opts.autoFetch && !association.autoFetch)) {
306 return cb();
307 }
308
309 // When we have a new non persisted instance for which the association field (eg owner_id)
310 // is set, we don't want to auto fetch anything, since `new Model(owner_id: 12)` takes no
311 // callback, and hence this lookup would complete at an arbitrary point in the future.
312 // The associated entity should probably be fetched when the instance is persisted.
313 if (Instance.isPersisted()) {
314 Instance[association.getAccessor]({ autoFetchLimit: opts.autoFetchLimit - 1 }, cb);
315 } else {
316 return cb();
317 }
318}
319
320function ucfirst(text) {
321 return text[0].toUpperCase() + text.substr(1);

Callers 1

One.jsFile · 0.70

Calls 1

cbFunction · 0.85

Tested by

no test coverage detected