Custom Table Mapping with Sequel gem

243 views Asked by At

Been spinning my wheels. How would one specify a custom table mapping with the sequel gem?

I've done the following

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

It complains about the 'myschema.MyModelTable' in the constructor. I've also tried set_dataset('myschema.MyModelTable') with no success.

The docs seem to be a bit opaque on how to do this

2

There are 2 answers

1
bgura On BEST ANSWER

I solved this with the following code

module Namespace
  class MyModel < Sequel::Model(Sequel.qualify(:myschema,:MyModelTable))
  end
end

More examples can be found in the tests here

0
v623 On

do this:

class MyModel < Sequel::Model(:myschema__MyModelTable)
end

there are two underscores. that's the convention Sequel's tinytds adapter uses to specify a schema. see line 194: https://github.com/jeremyevans/sequel/blob/master/lib/sequel/adapters/tinytds.rb