Replies: 3 comments
-
|
Ah! I found that this behavior is also documented here: https://sequel.jeremyevans.net/rdoc/files/doc/model_hooks_rdoc.html#label-Available+Hooks |
Beta Was this translation helpful? Give feedback.
-
|
Yes. This is expected behavior. The reason for this is that both plugin code as well as a significant number of models may need to run code necessary to save the object before validations are run, which shouldn't be skipped even if validations are skipped. I considered various ways to handle that, but the simplest is to just have the validation hooks always run, even if validation itself is skipped. |
Beta Was this translation helpful? Give feedback.
-
|
I see, thanks for the clarification. In case it is helpful our case was simple to fix by moving the code we wanted to avoid running multiple times from |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In the example below the
before_validationandafter_validationhooks are run twice when using nested_attributes to create associated records with amany_to_onerelationship (tracksonalbum_tracks), but the hooks are run once when using nested_attributes to create associated records with aone_to_manyrelationship (artistsonalbums).I was surprised that the
before_validationandafter_validationhooks would run at all whenvalidateis not going to run, but that looks purposeful (https://github.com/jeremyevans/sequel/blob/master/lib/sequel/model/base.rb#L1972-L1974), so not sure whether this is a bug or a just something to be aware of.Beta Was this translation helpful? Give feedback.
All reactions