Search code examples
rubysequel

Raise error from Sequel::Model if table does not exist?


I am starting to use Sequel for database connection handling in my Ruby application and hit a weird little snag. I created a model for my ETags table like so:

class ETag < Sequel::Model
end

Which should have gone out and found the etags table in my database, but it didn't. I think it was looking for e_tags instead, and created an empty model without any columns. The solution was to change it to this:

class Etag < Sequel::Model
end

Simple enough. However, I feel like my initial attempt should have raised an error. Is there a simple way to tell Sequel to raise an error when building a model if it can't find the underlying table in the database?


Solution

  • There currently is not a way to do this automatically. Trying to do it automatically would break many existing setups that do something like:

    class ETag < Sequel::Model
      set_dataset :etags
    end