My_object.save (false) DOES NOT REALLY skip my Active Record checks

So, I pull out my hair, eliminating this error that I was experiencing, and finally discovered that it causes it. It always seemed to me that when I called

@my_model.save(false)

That I would skip my ActiveRecord checks. It turns out that this is partly true. My objects are stored in the DESPITE database of my ActiveRecord scan. My problem exists because one of my checks changes one of the children's models during the checkout process (this is a 24-hour planning app, so when lunches are saved, I check them against the day they save, and the next day as well as to ensure that the user did not mean “2am” for a night shift.

My question is this: is there a way to actually skip my checks and go straight to the database? Is this the usual ActiveRecord behavior or should I dive deeper into my checks? Or am I out of luck and need to rewrite my checks?

+5
source share
4 answers

You can use before_create or another callback to interact with the record before storing it in the database, rather than trying to do it inside the validator.

Here is the documentation for ActiveRecord callbacks: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

, : http://guides.rubyonrails.org/activerecord_validations_callbacks.html

+6

,

, . !

+12

, . .

,

myobject.save_without_validation
+5

Orion, , , after_save.

+3

All Articles