mbroadst/thinkagain

View on GitHub
lib/document.js

Summary

Maintainability
F
2 wks
Test Coverage

File document.js has 951 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';
const Promise = require('bluebird'),
      Errors = require('./errors'),
      util = require('./util');

Severity: Major
Found in lib/document.js - About 2 days to fix

    Function _deleteHook has 145 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _deleteHook(docToDelete, deleteAll, deletedDocs, deleteSelf, updateParents, callback) {
        let model = this._getModel(); // instance of Model
        let r = model._thinkagain.r;
    
        let promises = [];
    Severity: Major
    Found in lib/document.js - About 5 hrs to fix

      Document has 42 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Document {
      
        /**
         * Create a document of a model (returned by `thinkagain.createModel`).
         * @param {function} model The model of this document
      Severity: Minor
      Found in lib/document.js - About 5 hrs to fix

        Function setSaved has 100 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          setSaved(all) {
            this.__proto__._saved = true; // eslint-disable-line
            if (all !== true) return;
            util.loopKeys(this._getModel()._joins, (joins, key) => {
              switch (joins[key].type) { // eslint-disable-line
        Severity: Major
        Found in lib/document.js - About 4 hrs to fix

          Function _saveLinks has 85 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _saveLinks(docToSave, saveAll) {
              let model = this._getModel();
              let constructor = this.getModel();
              let r = model._thinkagain.r;
          
          
          Severity: Major
          Found in lib/document.js - About 3 hrs to fix

            Function purge has 70 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              purge(callback) {
                let model = this._getModel(); // instance of Model
                let r = model._thinkagain.r;
            
                // Clean parent for hasOne
            Severity: Major
            Found in lib/document.js - About 2 hrs to fix

              Function _validateHook has 54 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                _validateHook(options, modelToValidate, validateAll, validatedModel, prefix) {
                  options = options || {};
              
                  let dataToValidate = this;
                  if (!!options.data) {
              Severity: Major
              Found in lib/document.js - About 2 hrs to fix

                Function _saveMany has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _saveMany(docToSave, saveAll, savedModel) {
                    let promises = [];
                    let model = this._getModel();
                    util.loopKeys(model._joins, (joins, key) => {
                      let join = joins[key];
                Severity: Minor
                Found in lib/document.js - About 2 hrs to fix

                  Function constructor has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    constructor(model, options) {
                      this.constructor = model;  // The constructor for this model
                      this._model = model._getModel(); // The instance of Model
                  
                      //TODO: We do not need to make a deep copy. We can do the same as for this._schemaOptions.
                  Severity: Minor
                  Found in lib/document.js - About 1 hr to fix

                    Function __makeSavableCopy has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                      __makeSavableCopy(doc, model, r) {
                        // model is an instance of a Model (for the top level fields), or undefined
                        let result, copyFlag;
                    
                        if (util.isPlainObject(doc) && (doc instanceof Buffer === false)) {
                    Severity: Minor
                    Found in lib/document.js - About 1 hr to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function __makeSavableCopy has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      __makeSavableCopy(doc, model, r) {
                        // model is an instance of a Model (for the top level fields), or undefined
                        let result, copyFlag;
                    
                        if (util.isPlainObject(doc) && (doc instanceof Buffer === false)) {
                    Severity: Minor
                    Found in lib/document.js - About 1 hr to fix

                      Function _onSavedBelongsTo has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        _onSavedBelongsTo(copy, docToSave, belongsToKeysSaved, saveAll, savedModel) {
                          let model = this._getModel();
                          let constructor = this.__proto__.constructor; // eslint-disable-line
                      
                          util.loopKeys(belongsToKeysSaved, (_joins, key) => {
                      Severity: Minor
                      Found in lib/document.js - About 1 hr to fix

                        Function _saveHook has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          _saveHook(docToSave, saveAll, savedModel) {
                            let model = this._getModel(); // instance of Model
                            let constructor = this.getModel();
                        
                            if (util.isPlainObject(docToSave) === false) {
                        Severity: Minor
                        Found in lib/document.js - About 1 hr to fix

                          Avoid deeply nested control flow statements.
                          Open

                                          if (constructor.getTableName() < joins[key].model.getTableName()) {
                                            newLink.id = this[joins[key].leftKey] + '_' + link;
                                          } else if (constructor.getTableName() > joins[key].model.getTableName()) {
                                            newLink.id = link + '_' + this[joins[key].leftKey];
                                          } else {
                          Severity: Major
                          Found in lib/document.js - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                            for (let k = 0, kk = joined[joinKey].length; k < kk; ++k) {
                                              if (joined[joinKey][k].doc === this) {
                                                joined[joinKey].splice(k, 1);
                                                return false;
                                              }
                            Severity: Major
                            Found in lib/document.js - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                            if (this[key][i].isSaved() === true) {
                                              newKeys[this[key][i][joins[key].rightKey]] = true;
                                            }
                              Severity: Major
                              Found in lib/document.js - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                            if (typeof this[key][i]._emitRetrieve === 'function') {
                                              this[key][i]._emitRetrieve();
                                            }
                                Severity: Major
                                Found in lib/document.js - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                if (this._getModel()._name === joins[key].model._getModel()._name) {
                                                  if (this[joins[key].leftKey] < this[key][i][joins[key].rightKey]) {
                                                    //TODO Add test for this
                                                    linksPks.push(this[joins[key].leftKey] + '_' + this[key][i][joins[key].rightKey]);
                                                  } else {
                                  Severity: Major
                                  Found in lib/document.js - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                    if (link < this[joins[key].leftKey]) {
                                                      newLink.id = link + '_' + this[joins[key].leftKey];
                                                    } else {
                                                      newLink.id = this[joins[key].leftKey] + '_' + link;
                                                    }
                                    Severity: Major
                                    Found in lib/document.js - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                  if (this.getModel()._getModel()._pk === joins[key].leftKey) {
                                                    if (this._getModel()._name < joins[key].model._getModel()._name) {
                                                      linksPks.push(this[joins[key].leftKey] + '_' + this[key][i][joins[key].rightKey]);
                                                    } else {
                                                      linksPks.push(this[key][i][joins[key].rightKey] + '_' + this[joins[key].leftKey]);
                                      Severity: Major
                                      Found in lib/document.js - About 45 mins to fix

                                        Function _validateHook has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                          _validateHook(options, modelToValidate, validateAll, validatedModel, prefix) {
                                            options = options || {};
                                        
                                            let dataToValidate = this;
                                            if (!!options.data) {
                                        Severity: Minor
                                        Found in lib/document.js - About 45 mins to fix

                                        Cognitive Complexity

                                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                        A method's cognitive complexity is based on a few simple rules:

                                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                        • Code is considered more complex for each "break in the linear flow of the code"
                                        • Code is considered more complex when "flow breaking structures are nested"

                                        Further reading

                                        Consider simplifying this complex logical expression.
                                        Open

                                              if (((key in docToSave) || (saveAll === true)) &&
                                                  (join.type === 'hasMany') && ((saveAll === false) || (savedModel[join.model.getTableName()] !== true))
                                                  && (Array.isArray(this[key]))) {
                                                savedModel[join.model.getTableName()] = true;
                                        
                                        
                                        Severity: Major
                                        Found in lib/document.js - About 40 mins to fix

                                          Function _syncValidate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                            _syncValidate(options) {
                                              let schemaOptions = this._getSchemaOptions();
                                              if (util.isPlainObject(schemaOptions)) {
                                                schemaOptions = util.mergeOptions(schemaOptions, options);
                                              } else {
                                          Severity: Minor
                                          Found in lib/document.js - About 25 mins to fix

                                          Cognitive Complexity

                                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                          A method's cognitive complexity is based on a few simple rules:

                                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                          • Code is considered more complex for each "break in the linear flow of the code"
                                          • Code is considered more complex when "flow breaking structures are nested"

                                          Further reading

                                          TODO found
                                          Open

                                              //TODO: We do not need to make a deep copy. We can do the same as for this._schemaOptions.
                                          Severity: Minor
                                          Found in lib/document.js by fixme

                                          TODO found
                                          Open

                                                            //TODO Add test for this
                                          Severity: Minor
                                          Found in lib/document.js by fixme

                                          TODO found
                                          Open

                                              //TODO Remove once
                                          Severity: Minor
                                          Found in lib/document.js by fixme

                                          TODO found
                                          Open

                                              //TODO Set a (string) id per document and use it to perform faster lookup
                                          Severity: Minor
                                          Found in lib/document.js by fixme

                                          TODO found
                                          Open

                                                  //TODO: Should we warn the users? Throw an error?
                                          Severity: Minor
                                          Found in lib/document.js by fixme

                                          TODO found
                                          Open

                                                      //TODO: Do we want to copy the foreign key value? If yes, there's no need for this loop
                                          Severity: Minor
                                          Found in lib/document.js by fixme

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              util.loopKeys(this.__proto__._parents._belongsLinks, (belongsLinks, key) => { // eslint-disable-line
                                                for (let i = 0, ii = belongsLinks[key].length; i < ii; ++i) {
                                                  let parentDoc = belongsLinks[key][i].doc;
                                                  let field = belongsLinks[key][i].key;
                                                  for (let j = 0, jj = parentDoc[field].length; j < jj; ++j) {
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 7 hrs to fix
                                          lib/document.js on lines 1264..1275

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 183.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              util.loopKeys(this.__proto__._parents._hasMany, (hasMany, key) => { // eslint-disable-line
                                                for (let i = 0, ii = hasMany[key].length; i < ii; ++i) {
                                                  let parentDoc = hasMany[key][i].doc;
                                                  let field = hasMany[key][i].key;
                                                  for (let j = 0, jj = parentDoc[field].length; j < jj; ++j) {
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 7 hrs to fix
                                          lib/document.js on lines 1278..1289

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 183.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Identical blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                        if (this._getModel()._name < joins[key].model._getModel()._name) {
                                                          linksPks.push(this[joins[key].leftKey] + '_' + this[key][i][joins[key].rightKey]);
                                                        } else {
                                                          linksPks.push(this[key][i][joins[key].rightKey] + '_' + this[joins[key].leftKey]);
                                                        }
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 5 hrs to fix
                                          lib/document.js on lines 1132..1136

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 147.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Identical blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                        } else if (this._getModel()._name < joins[key].model._getModel()._name) {
                                                          linksPks.push(this[joins[key].leftKey] + '_' + this[key][i][joins[key].rightKey]);
                                                        } else {
                                                          linksPks.push(this[key][i][joins[key].rightKey] + '_' + this[joins[key].leftKey]);
                                                        }
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 5 hrs to fix
                                          lib/document.js on lines 1141..1145

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 147.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                case 'hasMany':
                                                  if (Array.isArray(this[key])) {
                                                    for (let i = 0, ii = this[key].length; i < ii; ++i) {
                                                      if (this[key][i] instanceof Document) {
                                                        this[key][i].setSaved(true);
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 3 hrs to fix
                                          lib/document.js on lines 867..875

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 98.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                case 'hasAndBelongsToMany':
                                                  if (Array.isArray(this[key])) {
                                                    for (let i = 0, ii = this[key].length; i < ii; ++i) {
                                                      if (this[key][i] instanceof Document) {
                                                        this[key][i].setSaved(true);
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 3 hrs to fix
                                          lib/document.js on lines 857..865

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 98.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                    if (this[key][i].__proto__._parents._hasMany[this._getModel()._name] == null) { // eslint-disable-line
                                                      this[key][i].__proto__._parents._hasMany[this._getModel()._name] = []; // eslint-disable-line
                                                    }
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 947..949

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 93.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                    if (this[key][i].__proto__._parents._belongsLinks[this._getModel()._name] == null) { // eslint-disable-line
                                                      this[key][i].__proto__._parents._belongsLinks[this._getModel()._name] = []; // eslint-disable-line
                                                    }
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 926..928

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 93.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                  promises.push(r.table(joinedModel.getTableName()).getAll(this[join.leftKey], {index: join.rightKey}).replace(doc => {
                                                    return doc.without(join.rightKey);
                                                  }).run());
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 1317..1319

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 88.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                  promises.push(r.table(joinedModel.getTableName()).getAll(this[join.rightKey], {index: join.leftKey}).replace(doc => {
                                                    return doc.without(join.leftKey);
                                                  }).run());
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 1298..1300

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 88.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                  if (this[key].__proto__._parents._hasOne[this._getModel()._name] == null) { // eslint-disable-line
                                                    this[key].__proto__._parents._hasOne[this._getModel()._name] = []; // eslint-disable-line
                                                  }
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 902..904

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 85.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                    promises.push(r.table(join.link).getAll(this[join.leftKey], {index: this.getModel().getTableName() + '_' + join.leftKey}).delete().run());
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 1324..1324

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 85.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                  if (this[key].__proto__._parents._belongsTo[this._getModel()._name] == null) { // eslint-disable-line
                                                    this[key].__proto__._parents._belongsTo[this._getModel()._name] = []; // eslint-disable-line
                                                  }
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 891..893

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 85.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                    promises.push(r.table(join.link).getAll(this[join.rightKey], {index: this.getModel().getTableName() + '_' + join.rightKey}).delete().run());
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 1304..1304

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 85.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                    if (((this[key][i] instanceof Document) && (this[key][i].isSaved() === true))
                                                      && ((key in docToDelete) || ((deleteAll === true) && (deletedDocs.indexOf(this[key][i]) === -1)))) {
                                                      manyPromises.push(this[key][i]._delete(docToDelete[key], deleteAll, deletedDocs, true, false));
                                                    } else if ((this[key][i] instanceof Document) && (deletedDocs.indexOf(this[key][i]) === -1)) {
                                                      delete this[key][i][joins[key].rightKey];
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 1116..1147

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 79.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                    if (((this[key][i] instanceof Document) && (this[key][i].isSaved() === true))
                                                      && ((key in docToDelete) || ((deleteAll === true) && (deletedDocs.indexOf(this[key][i]) === -1)))) {
                                                      //pks.push(this[key][i][joins[key].model._getModel()._pk]);
                                                      docsToDelete.push(this[key][i]);
                                                      // We are going to do a range delete, but we still have to recurse
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 2 hrs to fix
                                          lib/document.js on lines 1092..1100

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 79.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Identical blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                  if ((this[key].isSaved() === true) &&
                                                    ((key in docToDelete) || ((deleteAll === true) && (deletedDocs.indexOf(this[key]) === -1)))) {
                                                    let deletePromise = this[key]._delete(docToDelete[key], deleteAll, deletedDocs, true, false)
                                                      .then(() => { delete this[key]; });
                                                    promises.push(deletePromise);
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 1 hr to fix
                                          lib/document.js on lines 1067..1077

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 64.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Identical blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                  if ((this[key].isSaved() === true) &&
                                                    ((key in docToDelete) || ((deleteAll === true) && (deletedDocs.indexOf(this[key]) === -1)))) {
                                                    let deletePromise = this[key]._delete(docToDelete[key], deleteAll, deletedDocs, true, false)
                                                      .then(() => { delete this[key]; });
                                                    promises.push(deletePromise);
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 1 hr to fix
                                          lib/document.js on lines 1081..1086

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 64.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              if (typeof docToDelete === 'function') {
                                                callback = docToDelete;
                                                deleteAll = true;
                                                docToDelete = {};
                                              } else {
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 1 hr to fix
                                          lib/document.js on lines 270..277

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 62.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              if (typeof docToSave === 'function') {
                                                callback = docToSave;
                                                saveAll = true;
                                                docToSave = {};
                                              } else {
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 1 hr to fix
                                          lib/document.js on lines 995..1002

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 62.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                    this[key][i].__proto__._parents._belongsLinks[this._getModel()._name].push({ // eslint-disable-line
                                                      doc: this,
                                                      key: key
                                                    });
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 1 hr to fix
                                          lib/document.js on lines 930..933

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 59.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                    this[key][i].__proto__._parents._hasMany[this._getModel()._name].push({ // eslint-disable-line
                                                      doc: this,
                                                      key: key
                                                    });
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 1 hr to fix
                                          lib/document.js on lines 951..954

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 59.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                if (((key in docToSave) || (saveAll === true)) &&
                                                    (join.type === 'hasAndBelongsToMany') && ((saveAll === false) || (savedModel[join.model.getTableName()] !== true))) {
                                                  savedModel[join.model.getTableName()] = true;
                                          
                                                  if (!Array.isArray(this[key])) {
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 1 hr to fix
                                          lib/document.js on lines 576..587

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 57.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                if (((key in docToSave) || (saveAll === true)) &&
                                                    (join.type === 'hasOne') && ((saveAll === false) || (savedModel[join.model.getTableName()] !== true))) {
                                                  savedModel[join.model.getTableName()] = true;
                                                  if (this[key] != null) { // eslint-disable-line
                                                    promises.push(this._saveManyHasOne(key, join, docToSave, saveAll, savedModel));
                                          Severity: Major
                                          Found in lib/document.js and 1 other location - About 1 hr to fix
                                          lib/document.js on lines 617..626

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 57.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Identical blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              if (typeof documentModel._validator === 'function') {
                                                if (documentModel._validator.call(this, this) === false) {
                                                  throw new Errors.ValidationError("Document's validator returned `false`.");
                                                }
                                              }
                                          Severity: Minor
                                          Found in lib/document.js and 1 other location - About 55 mins to fix
                                          lib/document.js on lines 195..199

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 54.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Identical blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                              if (typeof documentModel._validator === 'function') {
                                                if (documentModel._validator.call(this, this) === false) {
                                                  throw new Errors.ValidationError("Document's validator returned `false`.");
                                                }
                                              }
                                          Severity: Minor
                                          Found in lib/document.js and 1 other location - About 55 mins to fix
                                          lib/document.js on lines 156..160

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 54.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                          Open

                                                        if ((constructor.getTableName() === joins[key].model.getTableName())
                                                          && (joins[key].leftKey === joins[key].rightKey)) {
                                                          // We link on the same model and same key
                                                          // We don't want to save redundant field
                                                          if (link < this[joins[key].leftKey]) {
                                          Severity: Minor
                                          Found in lib/document.js and 1 other location - About 50 mins to fix
                                          lib/query.js on lines 373..401

                                          Duplicated Code

                                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                          Tuning

                                          This issue has a mass of 52.

                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                          Refactorings

                                          Further Reading

                                          There are no issues that match your filters.

                                          Category
                                          Status