Just tried that and yes, validation_helpers plugin is using getters for all validation methods, but auto_validations plugin is using values hash. In my opinion both should use getters. And in that case dafault_values will work as expected.
Dne neděle 22. března 2020 17:25:28 UTC+1 Petr Kaleta napsal(a): > > I understand that, but you should not get attribute value from underlaying > values hash, so if getter works, validations should also work. And as I > mentioned there's absolutely no issue with validation_helpers plugin and > everything works as expected. So there's a behaviour inconsistency in > auto_validations plugin... > > Dne neděle 22. března 2020 17:19:04 UTC+1 Jeremy Evans napsal(a): >> >> On Sunday, March 22, 2020 at 9:00:37 AM UTC-7, Petr Kaleta wrote: >>> >>> Hello, it looks like there's an issue when using both auto_validations >>> and defaults_setter plugin. >>> >>> I am using sequel 5.30.0 >>> >>> Please have a look on the following example: >>> >>> create_table :foo_bars do >>> primary_key :id >>> >>> column :name, 'character varying(64)', null: false >>> column :state, 'smallint', null: false >>> end >>> >>> class FooBar < Sequel::Model(:foo_bars) >>> plugin :auto_validations >>> plugin :defaults_setter >>> >>> default_values[:state] = 1 >>> end >>> >>> FooBar.create # => Sequel::ValidationFailed: state is not present >>> >>> With validation_helpers plugin I have no issues and everything works as >>> expected... >>> >> >> defaults_setter's documentation states: >> >> The defaults_setter plugin makes the column getter methods return the >> default values for new objects, if the values have not already been set. >> >> defaults_setter doesn't automatically set the values in the values hash >> before saving, but you can do that: >> >> class FooBar >> def before_validation >> super >> self.state ||= state >> end >> end >> >> So this isn't a bug, it is expected behavior. Note that older versions >> of defaults_setter (before Sequel 4) did eagerly set the default values >> when the model instance was created. That was changed for performance >> reasons. >> >> Note that the best way to fix your issue is to set 1 as the default for >> the state column in the database. >> >> 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/ec834503-3107-4ee2-b7a4-629048f803e9%40googlegroups.com.
