(columnName, data)
| 361 | }; |
| 362 | |
| 363 | containedIn(columnName, data) { |
| 364 | |
| 365 | var isCloudObject = false; |
| 366 | |
| 367 | var CbData = []; |
| 368 | if (columnName === 'id') |
| 369 | columnName = '_' + columnName; |
| 370 | |
| 371 | if (Object.prototype.toString.call(data) === '[object Object]' && !data instanceof CB.CloudObject) { //if object is passed as an argument |
| 372 | throw 'Array / value / CloudObject expected as an argument'; |
| 373 | } |
| 374 | |
| 375 | if (Object.prototype.toString.call(data) === '[object Array]') { //if array is passed, then replace the whole |
| 376 | |
| 377 | for (var i = 0; i < data.length; i++) { |
| 378 | if (data[i]instanceof CB.CloudObject) { |
| 379 | isCloudObject = true; |
| 380 | if (!data[i].id) { |
| 381 | throw "CloudObject passed should be saved and should have an id before being passed to containedIn"; |
| 382 | } |
| 383 | CbData.push(data[i].id); |
| 384 | } |
| 385 | } |
| 386 | if (CbData.length === 0) { |
| 387 | CbData = data; |
| 388 | } |
| 389 | |
| 390 | if (isCloudObject) { |
| 391 | columnName = columnName + '._id'; |
| 392 | } |
| 393 | |
| 394 | if (!this.query[columnName]) { |
| 395 | this.query[columnName] = {}; |
| 396 | } |
| 397 | |
| 398 | this.query[columnName]["$in"] = CbData; |
| 399 | var thisObj = this; |
| 400 | if (typeof this.query[columnName]["$nin"] !== 'undefined') { //for removing dublicates |
| 401 | CbData.forEach(function(val) { |
| 402 | if ((index = thisObj.query[columnName]["$nin"].indexOf(val)) >= 0) { |
| 403 | thisObj.query[columnName]["$nin"].splice(index, 1); |
| 404 | } |
| 405 | }); |
| 406 | } |
| 407 | } else { //if the argument is a string then push if it is not present already |
| 408 | |
| 409 | if (data instanceof CB.CloudObject) { |
| 410 | |
| 411 | if (!data.id) { |
| 412 | throw "CloudObject passed should be saved and should have an id before being passed to containedIn"; |
| 413 | } |
| 414 | |
| 415 | columnName = columnName + '._id'; |
| 416 | CbData = data.id; |
| 417 | } else |
| 418 | CbData = data; |
| 419 | |
| 420 | if (!this.query[columnName]) { |
no outgoing calls
no test coverage detected