lib/base/attributes.js
function(name, value) {
    if (!name && !value) return

    var values = name
    var castType = value
    var singleAssign = false
    if (typeof name === 'string') {
      values = {}
      values[name] = value
      castType = 'input'
      singleAssign = true
    }

    for (var field in this.definition.attributes) {
      if (this.definition.attributes.hasOwnProperty(field)) {
        var definition = this.definition.attributes[field]
        var fieldName = castType === 'input' ? definition.name : field

        if (singleAssign && values[fieldName] === undefined) {
          continue
        }

        value = values[fieldName]

        if (!singleAssign && value && typeof definition.setter === 'function') {
          definition.setter.call(this, value)
          continue
        }

        if (
          value === undefined &&
          this.attributes[field] === undefined &&
          definition.default !== undefined
        ) {
          if (typeof definition.default === 'function')
            value = definition.default()
          else value = this.definition.store.utils.clone(definition.default)
        }

        if (value === undefined && this.attributes[field] !== undefined) {
          value = this.attributes[field]
        }

        if (value === undefined) {
          value = null
        }

        // typecasted value
        castType = castType || 'input'

        if (!definition.type.cast[castType]) {
          castType = 'input'
        }

        value =
          value !== null
            ? this.definition.cast(field, value, castType, this)
            : null

        if (this.attributes[field] !== value) {
          if (value && typeof value === 'object') {
            // automatically set object tracking to true if the value is still an object after the casting
            definition.track_object_changes = true
          }

          if (
            definition.writable &&
            !(value === null && this.attributes[field] === undefined)
          ) {
            var beforeValue = this[field]
            var afterValue = value

            if (this.changes[field]) {
              this.changes[field][1] = afterValue
            } else {
              this.changes[field] = [beforeValue, afterValue]
            }
          }

          if (
            definition.track_object_changes &&
            (this.object_changes[field] === undefined || castType !== 'input')
          ) {
            // initial object hash
            this.object_changes[field] = [
              this.definition.store.utils.getHash(value),
              JSON.stringify(value)
            ]
          }

          if (definition.notifications) {
            definition.notifications.forEach(function(fn) {
              fn.call(this, value, castType)
            }, this)
          }

          this.attributes[field] = value

          // TODO: remove in 2.1!
          if (definition.emit_events && beforeValue !== value) {
            // emit old_value, new_value
            this.definition.emit(field + '_changed', this, beforeValue, value)
          }
        }
      }
    }

    return this
  }
function(name, value) {
    if (!name && !value) return

    var values = name
    var castType = value
    var singleAssign = false
    if (typeof name === 'string') {
      values = {}
      values[name] = value
      castType = 'input'
      singleAssign = true
    }

    for (var field in this.definition.attributes) {
      if (this.definition.attributes.hasOwnProperty(field)) {
        var definition = this.definition.attributes[field]
        var fieldName = castType === 'input' ? definition.name : field

        if (singleAssign && values[fieldName] === undefined) {
          continue
        }

        value = values[fieldName]

        if (!singleAssign && value && typeof definition.setter === 'function') {
          definition.setter.call(this, value)
          continue
        }

        if (
          value === undefined &&
          this.attributes[field] === undefined &&
          definition.default !== undefined
        ) {
          if (typeof definition.default === 'function')
            value = definition.default()
          else value = this.definition.store.utils.clone(definition.default)
        }

        if (value === undefined && this.attributes[field] !== undefined) {
          value = this.attributes[field]
        }

        if (value === undefined) {
          value = null
        }

        // typecasted value
        castType = castType || 'input'

        if (!definition.type.cast[castType]) {
          castType = 'input'
        }

        value =
          value !== null
            ? this.definition.cast(field, value, castType, this)
            : null

        if (this.attributes[field] !== value) {
          if (value && typeof value === 'object') {
            // automatically set object tracking to true if the value is still an object after the casting
            definition.track_object_changes = true
          }

          if (
            definition.writable &&
            !(value === null && this.attributes[field] === undefined)
          ) {
            var beforeValue = this[field]
            var afterValue = value

            if (this.changes[field]) {
              this.changes[field][1] = afterValue
            } else {
              this.changes[field] = [beforeValue, afterValue]
            }
          }

          if (
            definition.track_object_changes &&
            (this.object_changes[field] === undefined || castType !== 'input')
          ) {
            // initial object hash
            this.object_changes[field] = [
              this.definition.store.utils.getHash(value),
              JSON.stringify(value)
            ]
          }

          if (definition.notifications) {
            definition.notifications.forEach(function(fn) {
              fn.call(this, value, castType)
            }, this)
          }

          this.attributes[field] = value

          // TODO: remove in 2.1!
          if (definition.emit_events && beforeValue !== value) {
            // emit old_value, new_value
            this.definition.emit(field + '_changed', this, beforeValue, value)
          }
        }
      }
    }

    return this
  }
function ( name , value ) { if ( ! name && ! value ) return var values = name var castType = value var singleAssign = false if ( typeof name === 'string' ) { values = { } values [ name ] = value castType = 'input' singleAssign = true } for ( var field in this . definition . attributes ) { if ( this . definition . attributes . hasOwnProperty ( field ) ) { var definition = this . definition . attributes [ field ] var fieldName = castType === 'input' ? definition . name : field if ( singleAssign && values [ fieldName ] === undefined ) { continue } value = values [ fieldName ] if ( ! singleAssign && value && typeof definition . setter === 'function' ) { definition . setter . call ( this , value ) continue } if ( value === undefined && this . attributes [ field ] === undefined && definition . default !== undefined ) { if ( typeof definition . default === 'function' ) value = definition . default ( ) else value = this . definition . store . utils . clone ( definition . default ) } if ( value === undefined && this . attributes [ field ] !== undefined ) { value = this . attributes [ field ] } if ( value === undefined ) { value = null } // typecasted value castType = castType || 'input' if ( ! definition . type . cast [ castType ] ) { castType = 'input' } value = value !== null ? this . definition . cast ( field , value , castType , this ) : null if ( this . attributes [ field ] !== value ) { if ( value && typeof value === 'object' ) { // automatically set object tracking to true if the value is still an object after the casting definition . track_object_changes = true } if ( definition . writable && ! ( value === null && this . attributes [ field ] === undefined ) ) { var beforeValue = this [ field ] var afterValue = value if ( this . changes [ field ] ) { this . changes [ field ] [ 1 ] = afterValue } else { this . changes [ field ] = [ beforeValue , afterValue ] } } if ( definition . track_object_changes && ( this . object_changes [ field ] === undefined || castType !== 'input' ) ) { // initial object hash this . object_changes [ field ] = [ this . definition . store . utils . getHash ( value ) , JSON . stringify ( value ) ] } if ( definition . notifications ) { definition . notifications . forEach ( function ( fn ) { fn . call ( this , value , castType ) } , this ) } this . attributes [ field ] = value // TODO: remove in 2.1! if ( definition . emit_events && beforeValue !== value ) { // emit old_value, new_value this . definition . emit ( field + '_changed' , this , beforeValue , value ) } } } } return this }
Set one or multiple attributes of a Record.

@class Record
@method set
@param {string} name - The attributes name
@param {VALUE} value - The attributes value
@or
@param {object} attributes - Multiple attribute as an object
@param {string} cast_type - Optional cast_type name (Default: `input`)

@return {Record}
Set one or multiple attributes of a Record .