#62 Hacking ActiveRecord
Have you ever wanted to temporarily disable all validations? Well, ActiveRecord doesn't support this, but that doesn't mean we can't add it. This episode will show you how to open up an existing class and change its behavior.
- mp4Full Size H.264 Video (19 MB)
- m4vSmaller H.264 Video (12.2 MB)
- webmFull Size VP8 Video (39.2 MB)
- ogvFull Size Theora Video (28.2 MB)
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
alias_method_chain :valid?, :disable_check
@@disable_validation = true
@@disable_validation = false
@@disable_validation ||= false
Note there is a slight problem with how I set the default value for the class variable in the screencast. The code posted here should be correct.
Ideally I would use something like class_inheritable_accessor instead of a class variable, but I was unable to get this to work. Please comment if you have a suggestion.