Created
March 14, 2009 10:45
-
-
Save methodmissing/79042 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Reset id and @new_record if the transaction rolls back. | |
| def rollback_active_record_state! | |
| id_present = has_attribute?(self.class.primary_key) | |
| previous_id = id | |
| previous_new_record = new_record? | |
| yield | |
| rescue Exception | |
| @new_record = previous_new_record | |
| if id_present | |
| self.id = previous_id | |
| else | |
| @attributes.delete(self.class.primary_key) | |
| @attributes_cache.delete(self.class.primary_key) | |
| end | |
| raise | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment