Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is covered by save(:validate => false)?

I just implemented a number of custom counter_caches using code like this:

def after_save
    self.update_counter_cache
end
def after_destroy
    self.update_counter_cache
end
def update_counter_cache
    self.company.new_matchings_count = Matching.where(:read => false).count
    self.company.save
end

My question is this - what does the command Model.save(:validate => false) actually prevent beyond things like validates_with or before_validation?

Will my custom counter_caches be affected if I keep my existing saves without validation?

like image 236
sscirrus Avatar asked Mar 18 '11 18:03

sscirrus


1 Answers

Testing on Rails 4.2.6 shows that .save(:validate=>false) will actually skip before_validations and after_validation callbacks.

like image 102
lulalala Avatar answered Sep 28 '22 08:09

lulalala