Hello. I see that it is almost possible for sequel to work with multiple 
databases. But I've found a design issue.

require "sequel"


def db_scope(db)
  unless db.table_exists?(:authors)
    db.create_table :authors do
      primary_key :id
    end
  end


  unless db.table_exists?(:books)
    db.create_table :books do
      primary_key :id
    end
  end


  unless db.table_exists?(:authors_books)
    db.create_table :authors_books do
      primary_key :id
      foreign_key :author_id, :authors
      foreign_key :book_id, :books
    end
  end


  authors = Class.new Sequel::Model(db[:authors]) do
    many_to_many :books
  end


  books = Class.new Sequel::Model(db[:books]) do
    many_to_many :authors
  end


  authors.create.books
end


db_scope Sequel.connect("postgres://user@localhost")

We can see the following error:

uninitialized constant Book (this happened when attempting to find the 
associated class for 
#<Sequel::Model::Associations::ManyToManyAssociationReflection 
#<Class:0x00005654163d1fb0>.many_to_many :books>)

Sequel wants "::Book" class. But it is not possible to provide such class 
in global scope if we want to maintain multiple Books classes for multiple 
db client instances. Book could be defined in db scope, not in global 
scope. How to solve such question? Should I create a github issue?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to