简体   繁体   中英

Rails - don't rollback certain parts of a transaction

Is it possible to not rollback some parts of a transaction?

I'm trying to use an after_validation hook in a somewhat complex codebase where numerous parts are wrapped in a big transaction block. However, I want to save a log entry, regardless of whether the transaction as a whole fails and gets rollback.

I can't use after_rollback either, because that never gets called in certain instances.

The definition of transaction claims that it is Atomic - there is no need to split it into parts that can be rolled forward or back independently. In this SO thread you can get list of callbacks and choose which one suites your case to log needed info. Consider refactoring your code - split that operation into smaller operations (real transactions).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM