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

Function autoFetchInstance

lib/Associations/Extend.js:223–247  ·  view source on GitHub ↗
(Instance, association, opts, cb)

Source from the content-addressed store, hash-verified

221}
222
223function autoFetchInstance(Instance, association, opts, cb) {
224 if (!Instance.saved()) {
225 return cb();
226 }
227
228 if (!opts.hasOwnProperty("autoFetchLimit") || !opts.autoFetchLimit) {
229 opts.autoFetchLimit = association.autoFetchLimit;
230 }
231
232 if (opts.autoFetchLimit === 0 || (!opts.autoFetch && !association.autoFetch)) {
233 return cb();
234 }
235
236 if (Instance.isPersisted()) {
237 Instance[association.getAccessor]({ autoFetchLimit: opts.autoFetchLimit - 1 }, function (err, Assoc) {
238 if (!err) {
239 Instance[association.name] = Assoc;
240 }
241
242 return cb();
243 });
244 } else {
245 return cb();
246 }
247}
248
249function ucfirst(text) {
250 return text[0].toUpperCase() + text.substr(1);

Callers 1

Extend.jsFile · 0.70

Calls 1

cbFunction · 0.85

Tested by

no test coverage detected