On Mon, Nov 9, 2020 at 9:08 PM [email protected] < [email protected]> wrote:
> Is is possible to defer loading the dataset used for a Model until the > class is used rather than when the file is required? Currently, with an > empty database, the following file raises an error when required because > `some_table` does not exist yet: > > ``` > class MyModel < Sequel::Model(DB[:some_table]); end > ``` > > My use case is that I'm using Sequel in a Rails Engine. The above error > prevents running bin/rails db:* commands because the Rails application > along with my engine which raises the error. > I would have your model inherit from an abstract base class that doesn't require a valid table BaseClass = Class.new(Sequel::Model) BaseClass.require_valid_table = false class MyModel < BaseClass::Model(DB[:some_table]); end This only automatically rescues the error. You need to reset the dataset after the table is created if you want to later use the class in the same process. The correct solution is to use a strategy that doesn't load the models in migrations (or doesn't load models if the tables are not defined), so you can migrate to create the tables before loading the app. I'm not sure how to do that with Rails. There are alternatives to Rails that don't have these problems, and that's where I spend my time. Thanks, Jeremy -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CADGZSSf%3D3voNWtFvWc%3DYS7TiWH_ZjXue2%2BPSWV6u9_dGFOc__w%40mail.gmail.com.
