lib/base/conditions.js
function() {
    const Utils = this.definition.store.utils
    const self = this.chain()._unresolve() // if the collection is already resolved, return a unresolved and empty copy!

    const existingConditions = self.getInternal('conditions') || []
    const existingMap = {}

    existingConditions.forEach(function(cond) {
      const key =
        cond.type +
        '|' +
        cond.attribute +
        '|' +
        cond.operator +
        '|' +
        JSON.stringify(cond.value)
      existingMap[key] = true
    })

    var attributeNames = Object.keys(self.definition.attributes)

    attributeNames = attributeNames.concat(attributeNames.map(function(name){
      return self.definition.attributes[name].name
    }))

    const parentRelations = self.getInternal('parent_relations')
    const conditions = Utils.toConditionList(
      Utils.args(arguments),
      attributeNames
    )

    conditions.forEach(function(cond) {
      if (
        cond.type === 'relation' &&
        !self.definition.relations[cond.relation] &&
        !self.options.polymorph
      ) {
        throw new Error(
          'Can\'t find attribute or relation "' +
            cond.relation +
            '" for ' +
            self.definition.modelName
        )
      }
      // used for joins only
      if (parentRelations) {
        cond.parents = parentRelations
        if (cond.value && cond.value.$attribute && !cond.value.$parents) {
          cond.value.$parents = parentRelations
        }
      }

      if(cond.attribute) cond.attribute = self.store.toInternalAttributeName(cond.attribute)

      const key =
        cond.type +
        '|' +
        cond.attribute +
        '|' +
        cond.operator +
        '|' +
        JSON.stringify(cond.value)
      if (existingMap[key] && cond.type !== 'raw') return

      self.addInternal('conditions', cond)
    })

    return self
  }
function() {
    const Utils = this.definition.store.utils
    const self = this.chain()._unresolve() // if the collection is already resolved, return a unresolved and empty copy!

    const existingConditions = self.getInternal('conditions') || []
    const existingMap = {}

    existingConditions.forEach(function(cond) {
      const key =
        cond.type +
        '|' +
        cond.attribute +
        '|' +
        cond.operator +
        '|' +
        JSON.stringify(cond.value)
      existingMap[key] = true
    })

    var attributeNames = Object.keys(self.definition.attributes)

    attributeNames = attributeNames.concat(attributeNames.map(function(name){
      return self.definition.attributes[name].name
    }))

    const parentRelations = self.getInternal('parent_relations')
    const conditions = Utils.toConditionList(
      Utils.args(arguments),
      attributeNames
    )

    conditions.forEach(function(cond) {
      if (
        cond.type === 'relation' &&
        !self.definition.relations[cond.relation] &&
        !self.options.polymorph
      ) {
        throw new Error(
          'Can\'t find attribute or relation "' +
            cond.relation +
            '" for ' +
            self.definition.modelName
        )
      }
      // used for joins only
      if (parentRelations) {
        cond.parents = parentRelations
        if (cond.value && cond.value.$attribute && !cond.value.$parents) {
          cond.value.$parents = parentRelations
        }
      }

      if(cond.attribute) cond.attribute = self.store.toInternalAttributeName(cond.attribute)

      const key =
        cond.type +
        '|' +
        cond.attribute +
        '|' +
        cond.operator +
        '|' +
        JSON.stringify(cond.value)
      if (existingMap[key] && cond.type !== 'raw') return

      self.addInternal('conditions', cond)
    })

    return self
  }
function ( ) { const Utils = this . definition . store . utils const self = this . chain ( ) . _unresolve ( ) // if the collection is already resolved, return a unresolved and empty copy! const existingConditions = self . getInternal ( 'conditions' ) || [ ] const existingMap = { } existingConditions . forEach ( function ( cond ) { const key = cond . type + '|' + cond . attribute + '|' + cond . operator + '|' + JSON . stringify ( cond . value ) existingMap [ key ] = true } ) var attributeNames = Object . keys ( self . definition . attributes ) attributeNames = attributeNames . concat ( attributeNames . map ( function ( name ) { return self . definition . attributes [ name ] . name } ) ) const parentRelations = self . getInternal ( 'parent_relations' ) const conditions = Utils . toConditionList ( Utils . args ( arguments ) , attributeNames ) conditions . forEach ( function ( cond ) { if ( cond . type === 'relation' && ! self . definition . relations [ cond . relation ] && ! self . options . polymorph ) { throw new Error ( 'Can\'t find attribute or relation "' + cond . relation + '" for ' + self . definition . modelName ) } // used for joins only if ( parentRelations ) { cond . parents = parentRelations if ( cond . value && cond . value . $attribute && ! cond . value . $parents ) { cond . value . $parents = parentRelations } } if ( cond . attribute ) cond . attribute = self . store . toInternalAttributeName ( cond . attribute ) const key = cond . type + '|' + cond . attribute + '|' + cond . operator + '|' + JSON . stringify ( cond . value ) if ( existingMap [ key ] && cond . type !== 'raw' ) return self . addInternal ( 'conditions' , cond ) } ) return self }
Set some conditions

@public
@memberof Model
@method where
@param {(object|array)} conditions - every key-value pair will be translated into a condition

@return {Model}
Set some conditions