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

Function ChainFind

lib/ChainFind.js:10–292  ·  view source on GitHub ↗
(Model, opts)

Source from the content-addressed store, hash-verified

8module.exports = ChainFind;
9
10function ChainFind(Model, opts) {
11 var promiseFunctionPostfix = Model.settings.get('promiseFunctionPostfix');
12
13 var prepareConditions = function () {
14 return Utilities.transformPropertyNames(
15 opts.conditions, opts.properties
16 );
17 };
18
19 var prepareOrder = function () {
20 return Utilities.transformOrderPropertyNames(
21 opts.order, opts.properties
22 );
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

Callers

nothing calls this directly

Calls 14

chainRunFunction · 0.85
prepareConditionsFunction · 0.85
cbFunction · 0.85
prepareOrderFunction · 0.85
addChainMethodFunction · 0.85
callMethod · 0.80
onlyMethod · 0.80
runMethod · 0.80
filterMethod · 0.80
getMethod · 0.65
offsetMethod · 0.65
countMethod · 0.65

Tested by

no test coverage detected