stackmob-js-0.9.2.js
function(b){
        /*
         * Naming convention: A.or(B)
         */

        if (typeof this.orId == "undefined"){
          /*
           * If A is a normal AND query:
           * Clone A into newQuery
           * Clear newQuery's params
           * Assign OR Group# (1)
           * Prefix A params with and[#+1]
           * Prefix B params with and[#+1]
           * Prefix all params with or[#]
           * Set all of the above as newQuery.params
           * Return newQuery
           */

          var a = this;
          var newQuery = this.clone();

          newQuery['params'] = {};  // Reset params that will be populated below
          newQuery['orId'] = 1;     // Only allowed one OR, otherwise orCount++;
          newQuery['andCount'] = 1; // And counts are per or-clause

          var andCounter, keys, parsedAndString;

          // Determine [and#] prefix for A
          keys = _.keys(a.params);
          parsedAndString = "";
          if (keys.length > 1) {
            andCounter = newQuery['andCount']++;
            parsedAndString = andString(andCounter);
          }

          // Copy A's params to newQuery
          for (var key in a['params']){
            var newKey = orString(newQuery['orId']) + parsedAndString + key;
            newQuery['params'][newKey] = a['params'][key];
          }

          // Determine [and#] prefix for B
          keys = _.keys(b.params);
          parsedAndString = "";
          if (keys.length > 1) {
            andCounter = newQuery['andCount']++;
            parsedAndString = andString(andCounter);
          }

          // Copy B's params to newQuery
          for (key in b['params']){
            var newKey = orString(newQuery['orId']) + parsedAndString + key;
            if (typeof newQuery['params'][newKey] !== "undefined") {
              throw new Error("Error: You are attempting to OR two or more values for the same field. You should use an mustBeOneOf method instead.");
            } else {
              newQuery['params'][newKey] = b['params'][key];
            }
          }

          return newQuery;

        } else {
          /*
           * If A is already an OR query:
           * Clone A into newQuery
           * Prefix B with and[#+1]
           * Prefix B with or[A.orId]
           * Add B's params to newQuery
           * Return newQuery
           */

          var a = this;
          var newQuery = this.clone();

          // Determine [and#] prefix for B
          keys = _.keys(b.params);
          parsedAndString = "";
          if (keys.length > 1) {
            andCounter = newQuery['andCount']++;
            parsedAndString = andString(andCounter)
          }

          // Copy B's params to newQuery
          for (key in b['params']){
            var newKey = orString(newQuery['orId']) + parsedAndString + key;
            if (typeof newQuery['params'][newKey] !== "undefined") {
              throw new Error("Error: You are attempting to OR two or more values for the same field. You should use an mustBeOneOf method instead.");
            } else {
              newQuery['params'][newKey] = b['params'][key];
            }
          }

          return newQuery;
        }

      }
function(b){
        /*
         * Naming convention: A.or(B)
         */

        if (typeof this.orId == "undefined"){
          /*
           * If A is a normal AND query:
           * Clone A into newQuery
           * Clear newQuery's params
           * Assign OR Group# (1)
           * Prefix A params with and[#+1]
           * Prefix B params with and[#+1]
           * Prefix all params with or[#]
           * Set all of the above as newQuery.params
           * Return newQuery
           */

          var a = this;
          var newQuery = this.clone();

          newQuery['params'] = {};  // Reset params that will be populated below
          newQuery['orId'] = 1;     // Only allowed one OR, otherwise orCount++;
          newQuery['andCount'] = 1; // And counts are per or-clause

          var andCounter, keys, parsedAndString;

          // Determine [and#] prefix for A
          keys = _.keys(a.params);
          parsedAndString = "";
          if (keys.length > 1) {
            andCounter = newQuery['andCount']++;
            parsedAndString = andString(andCounter);
          }

          // Copy A's params to newQuery
          for (var key in a['params']){
            var newKey = orString(newQuery['orId']) + parsedAndString + key;
            newQuery['params'][newKey] = a['params'][key];
          }

          // Determine [and#] prefix for B
          keys = _.keys(b.params);
          parsedAndString = "";
          if (keys.length > 1) {
            andCounter = newQuery['andCount']++;
            parsedAndString = andString(andCounter);
          }

          // Copy B's params to newQuery
          for (key in b['params']){
            var newKey = orString(newQuery['orId']) + parsedAndString + key;
            if (typeof newQuery['params'][newKey] !== "undefined") {
              throw new Error("Error: You are attempting to OR two or more values for the same field. You should use an mustBeOneOf method instead.");
            } else {
              newQuery['params'][newKey] = b['params'][key];
            }
          }

          return newQuery;

        } else {
          /*
           * If A is already an OR query:
           * Clone A into newQuery
           * Prefix B with and[#+1]
           * Prefix B with or[A.orId]
           * Add B's params to newQuery
           * Return newQuery
           */

          var a = this;
          var newQuery = this.clone();

          // Determine [and#] prefix for B
          keys = _.keys(b.params);
          parsedAndString = "";
          if (keys.length > 1) {
            andCounter = newQuery['andCount']++;
            parsedAndString = andString(andCounter)
          }

          // Copy B's params to newQuery
          for (key in b['params']){
            var newKey = orString(newQuery['orId']) + parsedAndString + key;
            if (typeof newQuery['params'][newKey] !== "undefined") {
              throw new Error("Error: You are attempting to OR two or more values for the same field. You should use an mustBeOneOf method instead.");
            } else {
              newQuery['params'][newKey] = b['params'][key];
            }
          }

          return newQuery;
        }

      }
function ( b ) { /*
         * Naming convention: A.or(B)
         */ if ( typeof this . orId == "undefined" ) { /*
           * If A is a normal AND query:
           * Clone A into newQuery
           * Clear newQuery's params
           * Assign OR Group# (1)
           * Prefix A params with and[#+1]
           * Prefix B params with and[#+1]
           * Prefix all params with or[#]
           * Set all of the above as newQuery.params
           * Return newQuery
           */ var a = this ; var newQuery = this . clone ( ) ; newQuery [ 'params' ] = { } ; // Reset params that will be populated below newQuery [ 'orId' ] = 1 ; // Only allowed one OR, otherwise orCount++; newQuery [ 'andCount' ] = 1 ; // And counts are per or-clause var andCounter , keys , parsedAndString ; // Determine [and#] prefix for A keys = _ . keys ( a . params ) ; parsedAndString = "" ; if ( keys . length > 1 ) { andCounter = newQuery [ 'andCount' ] ++ ; parsedAndString = andString ( andCounter ) ; } // Copy A's params to newQuery for ( var key in a [ 'params' ] ) { var newKey = orString ( newQuery [ 'orId' ] ) + parsedAndString + key ; newQuery [ 'params' ] [ newKey ] = a [ 'params' ] [ key ] ; } // Determine [and#] prefix for B keys = _ . keys ( b . params ) ; parsedAndString = "" ; if ( keys . length > 1 ) { andCounter = newQuery [ 'andCount' ] ++ ; parsedAndString = andString ( andCounter ) ; } // Copy B's params to newQuery for ( key in b [ 'params' ] ) { var newKey = orString ( newQuery [ 'orId' ] ) + parsedAndString + key ; if ( typeof newQuery [ 'params' ] [ newKey ] !== "undefined" ) { throw new Error ( "Error: You are attempting to OR two or more values for the same field. You should use an mustBeOneOf method instead." ) ; } else { newQuery [ 'params' ] [ newKey ] = b [ 'params' ] [ key ] ; } } return newQuery ; } else { /*
           * If A is already an OR query:
           * Clone A into newQuery
           * Prefix B with and[#+1]
           * Prefix B with or[A.orId]
           * Add B's params to newQuery
           * Return newQuery
           */ var a = this ; var newQuery = this . clone ( ) ; // Determine [and#] prefix for B keys = _ . keys ( b . params ) ; parsedAndString = "" ; if ( keys . length > 1 ) { andCounter = newQuery [ 'andCount' ] ++ ; parsedAndString = andString ( andCounter ) } // Copy B's params to newQuery for ( key in b [ 'params' ] ) { var newKey = orString ( newQuery [ 'orId' ] ) + parsedAndString + key ; if ( typeof newQuery [ 'params' ] [ newKey ] !== "undefined" ) { throw new Error ( "Error: You are attempting to OR two or more values for the same field. You should use an mustBeOneOf method instead." ) ; } else { newQuery [ 'params' ] [ newKey ] = b [ 'params' ] [ key ] ; } } return newQuery ; } }
Combine a Query with an OR operator between it and
the current Query object.

Example:
var isAged  = new StackMob.Collection.Query().equals("age", "25");
var isNYC   = new StackMob.Collection.Query().equals("location", "NYC");
var notJohn = new StackMob.Collection.Query().notEquals("name", "john");
var notMary = new StackMob.Collection.Query().equals("location", "SF").notEquals("name", "mary");
var isLA    = new StackMob.Collection.Query().equals("location", "LA");

isAged.and( notJohn.or(notMary).or(isLA) );

@param  {StackMob.Collection.Query} b - A query object to OR with this object
@return {StackMob.Collection.Query} A new query equivalent to A OR B, where A is the object this method is called on and B is the parameter.
Combine a Query with an OR operator between it and the current Query object .