I want to update all sql statements for the queries generated for sql_for_insert, query, execute and update_sql for postgres. I'm using rails 3.2.17. Main aim is to change the column names to lower case. I tried to define a class "class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter" in initializers, methods are called over there, but I can't call super as my class isn't extended from any other class.
1 Answer
I got an alternate solution to just update the column names at one single location. I made a module and included it in Arel:Attributes:Attribute, this module converts the column names into lower case. This code is still under testing for me and not into production. But this seemed to have solved my problem.
module ArelAttributeWrapper
def self.included base
@actualname = nil
base.class_eval do
def initialize(*args)
super(*args)
@actualname = args[1]
end
def name=(value)
@actualname = value.downcase
end
def name
@actualname.downcase
end
end
end
end
Arel::Attributes::Attribute.send(:include, ArelAttributeWrapper)