activerecord-jdbc-adapter icon indicating copy to clipboard operation
activerecord-jdbc-adapter copied to clipboard

activerecord-jdbcmssql-adapter - uppercase legacy db column names

Open fun-ruby opened this issue 9 years ago • 2 comments

I am migrating an existing system that is using activerecord-sqlserver-adapter over to activerecord-jdbcmssql-adapter. The legacy database has all uppercase column names and was addressed with using an initializers configuration:

ActiveRecord::ConnectionAdapters::SQLServerAdapter.lowercase_schema_reflection = true

As far as I can tell there isn't an equivalent setting in activerecord-jdbcmssql-adapter. Please correct me if I am mistaken.

Since column_names are in uppercase, accessing attribute names in lowercase no longer works. I also observed setting the primary_key column name (in lowercase) have unintended result.

class Foo < ActiveRecord::Base self.primary_key = "foo_id" end

Foo.column_names => ["FOO_ID", ...] foo.attributes => {"FOO_ID" => 123, "foo_id" => nil}

This causes AR association look up to fail to find a match. For example, bar.foo => nil.

There are work-arounds but I was hoping for an equally elegant solution as with lowercase_schema_reflection.

Currently looking at aliasing column_names with lowercase equivalent, plus uppercasing all primary_key values.

Thanks in advance for any ideas.

Long


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

fun-ruby avatar Dec 03 '15 18:12 fun-ruby

Just ran into the same issue. +1 for a solution along the lines of lowercase_schema_reflection.

mortee avatar Dec 16 '15 01:12 mortee

if you guys need it than you should look into porting it over to AR-JDBC - we can not handle feature request (esp. for lesser used adapters such as MS-SQL) out of the box.

kares avatar Feb 22 '16 17:02 kares