jruby / activerecord-jdbc-adapter

JRuby's ActiveRecord adapter using JDBC.
BSD 2-Clause "Simplified" License
462 stars 387 forks source link

activerecord-jdbcmssql-adapter - uppercase legacy db column names #697

Open fun-ruby opened 8 years ago

fun-ruby commented 8 years ago

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!](https://www.bountysource.com/issues/28827582-activerecord-jdbcmssql-adapter-uppercase-legacy-db-column-names?utm_campaign=plugin&utm_content=tracker%2F136963&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F136963&utm_medium=issues&utm_source=github).
mortee commented 8 years ago

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

kares commented 8 years ago

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.