Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping callbacks and validation

Is there a way to skip callbacks and validation by doing something along these lines in Rails 3?

Object.save(:validate => false, :skip_callbacks => true)

Thanks!

like image 618
nbucciarelli Avatar asked Jun 30 '11 15:06

nbucciarelli


2 Answers

For skipping callbacks in Rails 3, you can use update_all for your given purpose.

Source: update_all

The full list for skipping callbacks are here:

  • decrement
  • decrement_counter
  • delete
  • delete_all
  • find_by_sql
  • increment
  • increment_counter
  • toggle
  • touch
  • update_column
  • update_all
  • update_counters

Source: Skipping Callbacks

like image 136
Jonathan Lin Avatar answered Sep 20 '22 05:09

Jonathan Lin


Object.save(:validate => false)

works as you would expect. So far as I know you cannot turn off callbacks (unless you return false from a before_ callback, but that then aborts the transaction).

like image 37
baldmark Avatar answered Sep 21 '22 05:09

baldmark