开发者

Rails Active Record - Quoted Identifiers - MS Sql Server reserved table names

I have a SQL Server 2005 legacy database which has a table named user and a model User which maps to the 'user' table.

'user' is a reserved word in Sql Server, so I need ActiveRecord to quote/bracket the table name in queries as

Select u.* from [user] where [user].[Id] = 1

the default is

Select u.* from user where user.[Id] = 1

which fails due to the reserve word conflict.

How do I inform rails to use use either the standard quoted identifiers or bracketed identifiers to delimit 开发者_JAVA百科reserved words and/or spaces in table names?

Rails Models

class User < UserBase
  set_primary_key "Id"
  set_table_name "user"

end

class UserBase < ActiveRecord::Base
  establish_connection "tums_#{[Rails.env]}"
  self.abstract_class = true
end


This was a bug in the jruby activerecord jdbc adapter source for MS Sql server. It has since been fixed.

https://github.com/jruby/activerecord-jdbc-adapter/issues/49

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜