rails/rails — pull request #7688 by VadimPushtaev (2012-09-18 19:25:56+00:00)
Title: update_attribute, update_column and update_columns should update readonly attributes

It was decided two year ago in c96a505391 that "update_attribute should not update readonly attributes". I believe it's missleading and should be changed.

I wrote an issue asking whether it's normal or not: rails/rails/issues/7679. As you can see, it was recommended to me to try sending pull request.

Reasons I believe `update_attribute`, `update_column` and `update_columns` should update readonly attributes:

1. All validations are skipped in this methods. Readonly check really looks like validation.
2. `update_attribute` is kind of more 'raw' version of `=` operator, but in this case I can do

```
minivan.color = 'new_color'
minivan.save
```

without getting exceptions, but can't do

```
minivan.update_attribute :color, 'new_color'
```

It's pretty weird, in this case `=` behaves more raw than `update_attribute`.

3. Readonly control is relarively low-level:

```
# Filters the primary keys and readonly attributes from the attribute names.
def attributes_for_update(attribute_names)
attribute_names.select do |name|
column_for_attribute(name) && !pk_attribute?(name) && !readonly_attribute?(name)
end
end
```
And here is one more oddity here: we don't raise exception for `pk_attribute`, but do for `readonly_attribute` in `update_attribute`, `update_column` and `update_columns`.

I'm open to discussion. Please, let me know where I'm wrong :)