I want to run Alarm.destroy_all
, though, each alarm is associated to many AlarmEvent
s, and each AlarmEvent
is associated to many AlarmEvent::Measurement
s,being both associations marked as :dependent=>destroy
So, when I invoke Alarm.destroy all, this invokation is taking ages to run. Is there any way I could make it faster? How?
Until now I've tried Alarm.joins(:alarm_events).destroy_all
and it is still slow.
The faster alternative to destroy_all
is delete_all
but this won't chase down and destroy any dependencies, nor will it trigger any before_destroy
or after_destroy
hooks.
If you're really concerned about speed, you'd probably re-write this with this in mind. You can even rack it up as a series of conditions:
Alarm.delete_all(:id => alarm_ids)
AlarmEvent.delete_all(:alarm_id => alarm_ids)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With