Satya's blog - Rails: Override Table Name Quoting
|
We had a situation where our Sybase database didn't appreciate that Ruby on Rails was quoting table names like so: [table_name]. The square brackets are okay in Sybase but our particular database was too old for it. So, I have to override table name quoting. In my Rails app, in config/initalizers/sybase_adapter.rb, I place this code:
# sybase_adapter.rb
# stolen from rails' to override the table name quoting. []-quoting throws off atlas server.
module ActiveRecord
module ConnectionAdapters
class SybaseAdapter < AbstractAdapter # :nodoc:
def quote_column_name(name)
# If column name is close to max length, skip the quotes, since they
# seem to count as part of the length.
name
#((name.to_s.length + 2) <= table_alias_length) ? "[#{name}]" : name.to_s
end
end # class SybaseAdapter
end # module ConnectionAdapters
end # module ActiveRecord
And it works. Table and column names are no longer quoted. Much thanks to folks on the #rubyonrails freenode IRC channel. Specific users: %w[ blj Bobnation defswork jammanbo rsl ].join(', '). Update: For some reason, this didn't work with active scaffold on Rails 2.1. Shrug. Last updated: Dec 04 2008 13:43 |
|