docs: function(node, deepLevel) {
            return new Ember.RSVP.Promise((resolve, reject) => {
              if (node.deepLevel === deepLevel) {
                let processData = () => {
                  if (node.relationType === 'belongsTo') {
                    if (node.parent.sorting !== node.propNameInParent) {
                      sortData(node.parent.data, node.propNameInParent);
                      node.parent.sorting = node.propNameInParent;
                    }
  
                    if (node.sorting !== node.primaryKeyName) {
                      sortData(node.data, node.primaryKeyName);
                      node.sorting = node.primaryKeyName;
                    }
  
                    joinSortedDataArrays(node.parent.data, node.propNameInParent, node.data, node.primaryKeyName, node.modelName, node.parent.modelName);
  
                  } else {
                    joinHasManyData(node.parent.data, node.propNameInParent,
                      getDetailsHashMap(node.data, node.primaryKeyName),
                      node.modelName, node.parent.modelName);
                  }
  
                  // Remove node from parent.expand.
                  let masters = Object.keys(node.parent.expand);
                  let mastersCount = masters.length;
                  let masterName;
                  let masterFound = false;
                  for (let i = 0; i < mastersCount; i++) {
                    masterName = masters[i];
                    if (node.parent.expand[masterName].propNameInParent === node.propNameInParent) {
                      masterFound = true;
                      break;
                    }
                  }
  
                  if (masterFound) {
                    delete node.parent.expand[masterName];
                  }
                };
  
                // Load and join data.
                let loadPromises = [];
  
                // If parent data is one record and relationship is belongsTo then apply filter by master id from parent data.
                let filterById;
  
                if (!node.parent.data) {
                  // Load parent data.
                  let nodeTable = _this._db.table(node.parent.modelName);
                  let loadPromise = new Ember.RSVP.Promise((loadResolve, loadReject) => {
                    nodeTable.toArray().then((data) => {
                      node.parent.data = data;
                      node.parent.sorting = node.parent.primaryKeyName;
                      loadResolve();
                    }, loadReject);});
                  loadPromises.push(loadPromise);
                } else if (node.parent.data.length === 1 && node.relationType === 'belongsTo') {
                  filterById = node.parent.data[0][node.propNameInParent];
                }
  
                if (!node.data) {
                  // Load data.
                  let nodeTable = _this._db.table(node.modelName);
                  if (filterById) {
                    nodeTable = nodeTable.where(node.primaryKeyName).equals(filterById);
                  }
  
                  let loadPromise = new Ember.RSVP.Promise((loadResolve, loadReject) => {nodeTable.toArray().then((data) => {
                    node.data = data;
                    node.sorting = node.primaryKeyName;
                    loadResolve();
                  }, loadReject);});
                  loadPromises.push(loadPromise);
                }
  
                Ember.RSVP.all(loadPromises).then(() => {
                  processData();
                  resolve();
                }, reject);
  
              } else {
                if (node.expand) {
                  let joinRelationsQueue = Queue.create();
                  joinRelationsQueue.set('continueOnError', false);
  
                  let masters = Object.keys(node.expand);
                  let mastersCount = masters.length;
                  let attachScanDeepLevelToRelationsQueue = (masterName) => {
                    joinRelationsQueue.attach((queryItemResolve, queryItemReject) => {
                      // load data for optimal performance.
                      let expandedMaster = node.expand[masterName];
                      let loadPromise;
                      let skipScan = false;
                      if (node.data && !expandedMaster.data) {
                        let nodeDataLength = node.data.length;
                        if (nodeDataLength === 0) {
                          skipScan = true;
                        } else if (nodeDataLength <= 50) { // Magical constant which depend on list form max rows.
                          let anyOfKeys = [];
  
                          for (let i = 0; i < nodeDataLength; i++) {
                            let relationKeyValue = node.data[i][masterName];
  
                            if (relationKeyValue) {
                              if (expandedMaster.relationType === 'belongsTo') {
                                anyOfKeys.push(relationKeyValue);
                              } else {
                                anyOfKeys = anyOfKeys.concat(relationKeyValue);
                              }
                            }
                          }
  
                          if (anyOfKeys.length === 0) {
                            skipScan = true;
                          } else {
                            loadPromise = new Ember.RSVP.Promise((loadResolve, loadReject) => {
                              _this._db.table(expandedMaster.modelName)
                              .where(expandedMaster.primaryKeyName)
                              .anyOf(anyOfKeys)
                              .toArray()
                              .then((loadedData) => {
                                expandedMaster.data = loadedData;
                                expandedMaster.sorting = expandedMaster.primaryKeyName;
                                loadResolve();
                              }, loadReject);
                            });
                          }
                        }
                      }
  
                      Ember.RSVP.all([loadPromise]).then(() => {
                        if (!skipScan) {
                          scanDeepLevel(expandedMaster, deepLevel).then(queryItemResolve, queryItemReject);
                        } else {
                          queryItemResolve();
                        }
                      });
                    });
                  };
  
                  for (let i = 0; i < mastersCount; i++) {
                    let masterName = masters[i];
                    attachScanDeepLevelToRelationsQueue(masterName);
                  }
  
                  joinRelationsQueue.attach((queueItemResolve) => {
                    resolve();
                    queueItemResolve();
                  });
                } else {
                  resolve();
                }
              }
            });
          }