<commit_before># Model: Mutators

## Date Mutators

By using `this.date()` attribute type, Vuex ORM will convert the field into [Moment](http://momentjs.com) instance, which provides great flexibility handling on date object.

```js
import { Model } from 'vuex-orm'

class User extends Model {
  static entity = 'users'

  static fields () {
    return {
      id: this.attr(null),
      name: this.attr(''),
      created_at: this.date(null)
    }
  }
}

const user = new User({ id: 1, name: 'John', created_at: '1985-10-10 00:00:00' })

user.created_at.format('MMM D, YYYY')

// Oct 10, 1985
```<commit_msg>Update doc<commit_after>Vuex ORM lets you define mutators which are going to modify the specific field when instantiating the Model. There are 2 ways to do this.

## Via Attribute

You can pass a closure to the 2nd argument of `attr` method. The closure takes the corresponding value as an argument, and you can modify the value however you want.

```js
import { Model } from 'vuex-orm'

class User extends Model {
  static entity = 'users'

  static fields () {
    return {
      id: this.attr(null),
      name: this.attr('', value => value.toUpperCase())
    }
  }
}

const user = new User({ name: '<NAME>' })

user.name

// <NAME>
```

## Vie Mutators Method

You can also define mutators in one place by creating `static mutators` method. The `mutators` method should return an object containing a function with the key of the corresponding field.

```js
import { Model } from 'vuex-orm'

class User extends Model {
  static entity = 'users'

  static fields () {
    return {
      name: this.attr('')
    }
  }

  static mutators () {
    return {
      name (value) {
        return value.toUpperCase()
      }
    }
  }
}

const user = new User({ name: '<NAME>' })

user.name

// <NAME>
```

Note that if you have mutator defined at the 2nd argument of the `attr`, and also have mutators method with the same field name, the mutator at `attr` takes the president.
{'fraction_non_alphanumeric': 0.11402623612512613, 'fraction_numerical': 0.012108980827447022, 'mean_word_length': 3.210191082802548, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '199272', 'n_tokens_mistral': 637, 'n_tokens_neox': 603, 'n_words': 248}