开发者

Using activerecord on a table with a colum `changed` raises error

A legacy database has a column changed (containing an updated_at timestamp).

This results in an error changed? is defined by ActiveRecord, but only when I open its association.

I have tried to:

开发者_运维技巧
  • override instance_method_already_implemented?
  • And to alias that column.
  • To add custom methods using write_attribute and read_attribute.

But none of that avoids the failure.

Can a changed column exist? At all? I would prefer not to have to alter the table, because that means changing a lot of legacycode too.


One of the few downsides to ActiveRecord are all the already-taken attribute names. This is one of them, and it can be an error-prone nightmare to work around ActiveRecord's declarations.

If your database supports them, you could create a view of the table just to present different column names to ActiveRecord.


Try disabling partial updates in ActiveRecord in your initializer:

ActiveRecord::Base.partial_updates = false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜