auto_validations plugin: how to disable unique validations on all models

9 views
Skip to first unread message

petr....@me.com

unread,
Sep 1, 2021, 9:13:55 AMSep 1
to sequel-talk
Hi,
how can I disable/skip unique auto validations on all models?

I've tried Sequel::Model.skip_auto_validations(:unique) but it's not working...

Jeremy Evans

unread,
Sep 1, 2021, 10:38:45 AMSep 1
to seque...@googlegroups.com
skip_auto_validations only affects the specific model you call it on, it doesn't affect all subclasses.

The simplest way is probably the following after loading the plugin:

def (Sequel::Model).auto_validate_unique_columns
  []
end
 
Thanks,
Jeremy

petr....@me.com

unread,
Sep 2, 2021, 9:30:39 AMSep 2
to sequel-talk
Hey Jeremy,
thank you for your answer. What do you think about this solution?

Sequel::Model.plugin :subclasses do |sub_class|
  sub_class.skip_auto_validations(:unique)
end

Dne středa 1. září 2021 v 16:38:45 UTC+2 uživatel Jeremy Evans napsal:

Jeremy Evans

unread,
Sep 2, 2021, 10:14:34 AMSep 2
to seque...@googlegroups.com
On Thu, Sep 2, 2021 at 6:30 AM 'petr....@me.com' via sequel-talk <seque...@googlegroups.com> wrote:
Hey Jeremy,
thank you for your answer. What do you think about this solution?

Sequel::Model.plugin :subclasses do |sub_class|
  sub_class.skip_auto_validations(:unique)
end

Sure, that should also work just fine.

Thanks,
Jeremy
Reply all
Reply to author
Forward
0 new messages