Forum: Ruby on Rails Getting AR to downcase table and column names

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
31b6446447a4da5157bb67cc4c6afc64?d=identicon&s=25 John Kodis (Guest)
on 2006-03-13 17:42
(Received via mailing list)
I'm looking for the cleanest way to force the Rails framework to use a
lower-case version of the table and column names in a database when
creating records.

I need this for a Rails application that displays the status of an
existing backup system.  The backup system (Bacula; Nice backup
system, BTW) can use either Postgres or Mysql as its database engine.
Unfortunately, the table and column names are created in all lower
case when using Postgres, and in StudlyCaps when using Mysql.  I'd
like my application to be able to work against either database type
without having to modify the capitalization of all the table and
column names in the application code.

The best approach that I've found so far is to conditionally override
the accessor methods, like so:

    class Pool < ActiveRecord::Base
      Pool.table_name = 'pool'
      Pool.primary_key = 'poolid'

      if STUDLY
	Pool.table_name = 'Pool'
	def id; self.PoolId; end
	def name; self.Name; end
	def volretention; self.VolRetention; end
      end
    end

While this works, it's not very elegant.  I'd much prefer some
application-wide "downcase field names" setting, but haven't found any
way to force this behavior.  Any hints would be greatly appreciated.

-- John Kodis.
This topic is locked and can not be replied to.