Jeremy, Currently we take advantage of not requiring a valid table for the purpose of being able to use sequel's validation framework with objects that are not database models. We created a "tabless_model" plugin to help us achieve this. We do this for consistency within the application. We don't want to mix sequel validations (for Sequel::Model classes) with ActiveModel validations (for PORO classes) within the same app. For my usage, having the model validation framework (with the errors object) broken out into it's own module that we can use with objects that don't extend Sequel::Model would be awesome.
Thanks, Matt On Monday, May 8, 2017 at 6:27:57 PM UTC-5, Jeremy Evans wrote: > > 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.
