Guest User

Untitled

a guest
May 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. # Used to get around the pesky camel case dbs such as MSSQL when u can't change them.
  2. # Adds reader and writer methods for the columns.
  3.  
  4. # add 'fix_camelcase_columns' into your model.
  5.  
  6. class ActiveRecord::Base
  7. def self.fix_camelcase_columns
  8. define_method :after_find do
  9. self.class.columns.each do |column|
  10. self.instance_eval("def #{column.name.underscore}; self.#{column.name}; end;")
  11. self.instance_eval("def #{column.name.underscore}=(x); self.#{column.name}=x; end;")
  12. end
  13. end
  14. end
  15. end
Add Comment
Please, Sign In to add comment