activerecord - Custom Named Attributes in Rails -
Whether it is possible to customize / override the name of an attribute in ActiveRecord, so that it does not match the column name in the database. ?
In my specific case there is a legacy column, "amendment", that I can not remove at this time, the name of the column conflicts with actions_as_audited. Until I complete my migration, which of the necessary legacy code I have for those errors?
The solution I want to override the attribute name for this column, and some areas that call it need to be updated. Thus, to allow legacy columns living with law_a_audited.
I have acts_as_audited
, but I'm assuming that its implementation is that column For the accelerator being overridden. In that case, you should be able to do just that:
class ActiveRecord :: base def self.name_column (column_name, new_name) define_method (new_name) {read_attribute column_name} define_method ("# {New_name} = ") {| Price | Write_attribute column_name, value} define_method ("# {new_name}?") {Attribute_present? Column_name} end end
These overrides will reach the column called column_name
without going through the accessor.
Oh, bonus duplication - destroying metaprogramming response:
Comments
Post a Comment