all files / lib/waterline/model/lib/ association.js

95.65% Statements 22/23
83.33% Branches 5/6
100% Functions 7/7
95.65% Lines 22/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64          1080× 1080× 1080×                   285× 285× 285×                       3881× 3881×           3881× 195×     194×       3881× 26×     25×       3881×    
 
/**
 * Handles an Association
 */
 
var Association = module.exports = function() {
  this.addModels = [];
  this.removeModels = [];
  this.value = [];
};
 
/**
 * Set Value
 *
 * @param {Number|Object} value
 * @api private
 */
 
Association.prototype._setValue = function(value) {
  Eif (Array.isArray(value)) {
    this.value = value;
    return;
  }
 
  this.value = this.value = [value];
};
 
/**
 * Get Value
 *
 * @api private
 */
 
Association.prototype._getValue = function() {
  var self = this;
  var value = this.value;
 
  // Attach association methods to values array
  // This allows access using the getter and the desired
  // API for synchronously adding and removing associations.
 
  value.add = function add(obj) {
    if (Array.isArray(obj)) {
      obj.forEach(function(el) {
        self.addModels.push(el);
      });
    } else {
      self.addModels.push(obj);
    }
  };
 
  value.remove = function remove(obj) {
    if (Array.isArray(obj)) {
      obj.forEach(function(el) {
        self.removeModels.push(el);
      });
    } else {
      self.removeModels.push(obj);
    }
  };
 
  return value;
};