RubyMoney/money-rails — pull request #145 by cbartlett (2013-11-29 03:55:42+00:00)
Title: Allow per-attribute disabling of validations

*Now with documentation and updated contributor list!*

I'd love some feedback on this. This feature allows disabling of validations on an individual attribute level, rather than only globally.

I have an app with several monetized columns that are aggregates. Example, in this `User` model:

```
has_many :accounts
monetize :balance_cents

def balance_cents
accounts.sum(:balance_cents)
end
```

This has the unfortunate side effect of causing database calls to get the sums on every save. In this app, one model has 3 such aggregate columns causing a total of 6 unnecessary queries. I don't want to disable all validations, just the ones for this model since they are already validated upon input on the `Account` model. I've added a new `disable_validation` option like so:

```
monetize :balance_cents, disable_validation: true
```

Which then doesn't validate the column on this `User` model. The net effect is that the unnecessary database reads are eliminated.