How to hide a database column from ActiveRecord?

David Scheffel wrote:

Can I tell ActiveRecord to ignore this column and not to add it to the Attributes array?

I submitted a patch at http://dev.rubyonrails.org/ticket/6896 which adds an attr_readonly method to ActiveRecord::Base to ignore attributes in update queries. It also fixes a bug with counter_cache. Hopefully it receives enough support and provides enough value to be applied, but if not I can make it into a plugin.

Dan Manges

David Scheffel wrote:

I'm really looking forward to it. How could I get notice about the next Rails release including this patch?

You can subscribe to the RSS feed for the patch here: http://dev.rubyonrails.org/ticket/6896?format=rss

You may also want to leave a comment on the patch stating that you would like to see the patch applied. If you have time, try checking out Rails trunk, applying the patch, and leaving a comment confirming that the patch works.

Dan Manges

Dan Manges wrote:

I submitted a patch at http://dev.rubyonrails.org/ticket/6896 which adds an attr_readonly method to ActiveRecord::Base to ignore attributes in update queries. It also fixes a bug with counter_cache. Hopefully it receives enough support and provides enough value to be applied, but if not I can make it into a plugin.

I think attr_readonly is a good solution if a different solution that tracks and only updates changed attributes is not going to be implemented.

Something's really needed to prevent a save writing to attributes that are also being updated through direct database update calls (used to most easily and properly handle concurrency).