Thank you On Sunday, August 29, 2021 at 11:24:57 AM UTC-4 Jeremy Evans wrote:
> On Sat, Aug 28, 2021 at 8:22 PM [email protected] <[email protected]> wrote: > >> OK, understood. How do I insist on required parameters, named or >> otherwise? >> > > Probably easiest to check for values after calling super: > > def initialize(values={}) > super > raise ArgumentError unless some_criteria > # ... > end > > Note that this approach makes little sense in Sequel. In Sequel, you can > do: > > Model.new(values).save > > but you can also do: > > Model.new.set(values).save > > So checking for values in initialize does not make sense. Sequel::Model > expects you to override validate and call super: > > def validate > super > errors.add(:column1, "doesn't meet criteria") unless some_criteria > end > > validate is called before saving the model. > > There are numerous plugins that offer additional validation methods and > approaches. > > 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/f4550c3d-9427-4c0d-9dfc-a9383212f8f3n%40googlegroups.com.
