Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

before_save , before_validation :on => :save

I wanted add a hook on before_save. Validation happens before "before_save" is called, so I moved it to before_validation :on =>:save.

Now the problem is, when I do @object.save_without_validation (sometimes I had to use this). my before_validation hook doesn't get called.

Am I missing something or is there a more robust way of adding a before hook that works for both cases?

like image 684
Rex Chung Avatar asked Oct 24 '10 07:10

Rex Chung


1 Answers

Hi when you save an object you have next callbacks

* before_validation
* after_validation
* before_save
* after_save
* before_create
* around_create
* after_create

try to place your code inside after_validation

like image 137
Bohdan Avatar answered Sep 28 '22 01:09

Bohdan