rails/activerecord/lib
Sean Griffin d937a1175f destroy shouldn't raise when child associations fail to save
Deep down in the association internals, we're calling `destroy!` rather
than `destroy` when handling things like `dependent` or autosave
association callbacks. Unfortunately, due to the structure of the code
(e.g. it uses callbacks for everything), it's nearly impossible to pass
whether to call `destroy` or `destroy!` down to where we actually need
it.

As such, we have to do some legwork to handle this. Since the callbacks
are what actually raise the exception, we need to rescue it in
`ActiveRecord::Callbacks`, rather than `ActiveRecord::Persistence` where
it matters. (As an aside, if this code wasn't so callback heavy, it
would handling this would likely be as simple as changing `destroy` to
call `destroy!` instead of the other way around).

Since we don't want to lose the exception when `destroy!` is called (in
particular, we don't want the value of the `record` field to change to
the parent class), we have to do some additional legwork to hold onto it
where we can use it.

Again, all of this is ugly and there is definitely a better way to do
this. However, barring a much more significant re-architecting for what
I consider to be a reletively minor improvement, I'm willing to take
this small hit to the flow of this code (begrudgingly).
2015-07-24 09:13:20 -06:00
..
active_record destroy shouldn't raise when child associations fail to save 2015-07-24 09:13:20 -06:00
rails/generators [ci skip] Correct grammar, add docs to ActiveRecord migration generator 2015-04-28 13:34:13 -07:00
active_record.rb Autoload ActiveRecord::RecordInvalid 2015-06-18 18:36:16 -03:00