Ruby 使用Sequel gem自定义表映射

Ruby 使用Sequel gem自定义表映射,ruby,sequel,sequel-gem,Ruby,Sequel,Sequel Gem,我一直在转动轮子。如何使用sequel gem指定自定义表映射 我做了以下几件事 init.rb OTHER_DB = Sequel.connect(:adapter => 'tinytds', :host => 'host1', :database => 'mydatabase', :user => 'myuser', :password => 'mypassword') Namespace::MyModel.db = OTHER_DB MyModel.rb

我一直在转动轮子。如何使用sequel gem指定自定义表映射

我做了以下几件事

init.rb

OTHER_DB = Sequel.connect(:adapter => 'tinytds', :host => 'host1', :database => 'mydatabase', :user => 'myuser', :password => 'mypassword')

Namespace::MyModel.db = OTHER_DB
MyModel.rb

module Namespace
  class MyModel < Sequel::Model('myschema.MyModelTable')
  end
end
模块名称空间
类MyModel
它抱怨构造函数中的“myschema.MyModelTable”。我还尝试了set_数据集('myschema.MyModelTable'),但没有成功


文档似乎有点不清楚如何做到这一点

我用下面的代码解决了这个问题

module Namespace
  class MyModel < Sequel::Model(Sequel.qualify(:myschema,:MyModelTable))
  end
end
模块名称空间
类MyModel

更多的例子可以在测试中找到

我用下面的代码解决了这个问题

module Namespace
  class MyModel < Sequel::Model(Sequel.qualify(:myschema,:MyModelTable))
  end
end
模块名称空间
类MyModel
更多示例可在测试中找到,请执行以下操作:

class MyModel < Sequel::Model(:myschema__MyModelTable)
end
classmymodel
这里有两个下划线。这是Sequel的tinytds适配器用于指定模式的约定。请参见第194行:

执行以下操作:

class MyModel < Sequel::Model(:myschema__MyModelTable)
end
classmymodel
这里有两个下划线。这是Sequel的tinytds适配器用于指定模式的约定。见第194行: