MCPcopy Index your code
hub / github.com/dresende/node-orm2 / chainRun

Function chainRun

lib/ChainFind.js:25–91  ·  view source on GitHub ↗
(done)

Source from the content-addressed store, hash-verified

23 };
24
25 var chainRun = function (done) {
26 var order, conditions;
27
28 conditions = Utilities.transformPropertyNames(
29 opts.conditions, opts.properties
30 );
31 order = Utilities.transformOrderPropertyNames(
32 opts.order, opts.properties
33 );
34
35 opts.driver.find(opts.only, opts.table, conditions, {
36 limit : opts.limit,
37 order : order,
38 merge : opts.merge,
39 offset : opts.offset,
40 exists : opts.exists
41 }, function (err, dataItems) {
42 if (err) {
43 return done(err);
44 }
45 if (dataItems.length === 0) {
46 return done(null, []);
47 }
48
49 var eagerLoad = function (err, items) {
50 var idMap = {};
51
52 var keys = _.map(items, function (item, index) {
53 var key = item[opts.keys[0]];
54 // Create the association arrays
55 for (var i = 0, association; association = opts.__eager[i]; i++) {
56 item[association.name] = [];
57 }
58 idMap[key] = index;
59
60 return key;
61 });
62
63 async.eachSeries(opts.__eager,
64 function (association, cb) {
65 opts.driver.eagerQuery(association, opts, keys, function (err, instances) {
66 if (err) return cb(err)
67
68 for (var i = 0, instance; instance = instances[i]; i++) {
69 // Perform a parent lookup with $p, and initialize it as an instance.
70 items[idMap[instance.$p]][association.name].push(association.model(instance));
71 }
72 cb();
73 });
74 },
75 function (err) {
76 if (err) done(err);
77 else done(null, items);
78 }
79 );
80 };
81
82 async.map(dataItems, opts.newInstance, function (err, items) {

Callers 1

ChainFindFunction · 0.85

Calls 1

findMethod · 0.65

Tested by

no test coverage detected