Currently, Sequel allows the creation of model subclasses even if the 
related database table does not exist. 

Unfortunately, this hides bugs.  For example, if you do:

  class Foo < Sequel::Model
  end

and the foos table does not exist, no error is generated until you actually 
try to use the Foo model.

The historical reason for this is to allow set_dataset to work after 
defining the model class:

  class Foo < Sequel::Model
    set_dataset :my_foo
  end

Also, it allows the (already deprecated) schema plugin to work:

  class Foo < Sequel::Model
    plugin :schema
    create_table?(:my_foo) do
      primary_key :id
      String :bar
    end
  end

For a long time, it's been recommended to use the following format when you 
need to override the table name instead of calling set_dataset after 
creating the class:

  class Foo < Sequel::Model(:my_foo)
  end

And if you need to modify the schema, it has been recommended for a long 
time to do it before defining the model:

  DB.create_table?(:my_foo) do
    primary_key :id
    String :bar
  end

  class Foo < Sequel::Model(:my_foo)
  end

This ensures that when the class is created, the appropriate table exists 
and the table is actually usable.

Sequel has supported requiring a valid table at model class creation time 
since 4.33.0, via:

  Sequel::Model.require_valid_table = true

I am considering requiring a valid table by default in Sequel 5, and having 
users do "Sequel::Model.require_valid_table = false" if they want the 
current behavior. I would like some feedback from the community before 
making a final decision.

Thanks,
Jeremy

P.S. Note that this does not affect anonymous class creation (for abstract 
model base classes):

 BaseClass = Class.new(Sequel::Model)

as Sequel doesn't not attempt to assign a dataset to the class in that case.

-- 
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 post to this group, send email to [email protected].
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