rails/rails — pull request #8464 by VadimPushtaev (2012-12-08 09:19:26+00:00)
Title: update_attribute, update_column and update_columns should update readonly attributes

*This is a new version of broken #7688*

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

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

without getting exceptions, but can't do

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

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

3. Readonly control is relatively low-level:

```ruby
# 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: we don't raise exception for `pk_attribute`, but do for `readonly_attribute` in `update_attribute`, `update_column` and `update_columns`.

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