ruby-on-railssoft-deleteglobalize

Rails - Globalize and Permanent_record dependent: :destroy callbacks


In a Rails 4.2 project I use gem 'permanent_records' to handle records soft-deletion and gem 'globalize' for translations.

Globalize sets the following relationships between the translated Model and the Translation Model (source):

has_many :translations, :class_name  => translation_class.name,
                                :foreign_key => options[:foreign_key],
                                :dependent   => :destroy,
                                :extend      => HasManyExtensions,
                                :autosave    => true,
                                :inverse_of  => :globalized_model

The result is that calling :destroy on the translated Model, does not delete it (which is what permanent_records is used for), but I lose the related translations, which I'd like to keep alive.

Shall I override the dependent: :destroy callback only on some translated models (the translated models where I use permanent_records)? How to do it properly?

Is there any other way to get the desired result?


Solution

  • I finally solved the issue by adding a deleted_at attribute to GlobalizedModel::Translation Model (in my case Treatment::Translation) so that also translations are soft-deleted.