I want something like alias_attribute
for make a full alias for column from DB. For example I have a table with many columns named like UGLYCOLUMN
.
Using it in a query is very uncomfortable:
MyModel.where('UglyColumn'.upcase => 'value')
I want some kind of:
class MyModel < ActiveRecord::Base
awesome_alias_attribute {'UGLYCOLUMN' => :pretty_column, ...}
...
end
And then use MyModel.where(pretty_column: 'value')
instead of MyModel.where('UglyColumn'.upcase => 'value')
.
Moreover it must work for complex query MyModel.joins(:other_relation).where(my_models: {pretty_column: 'value'})
and so on.
In a perfect case it must work with all ActiveRecord methods and properties. I.e. if I firstly create an alias for primary key awesome_alias_attribute :UGLYPRIMARYKEY, :id
, then I want say self.primary_key = :id
and have a profit.