Skip to content
Snippets Groups Projects
Unverified Commit e6f2b4b4 authored by Pierre-André Boissinot's avatar Pierre-André Boissinot Committed by GitHub
Browse files

Gère la suppression ou non des translations lorsqu'on supprime un objet direct ou indirect (#2001)

parent 5fb68be2
No related branches found
Tags v2.2.2
No related merge requests found
......@@ -53,6 +53,7 @@ gem "kaminari"
gem "leaflet-rails"
gem "libretranslate"#, path: "../libretranslate"
gem "mini_magick"
gem "observer", "~> 0.1.2"
gem "octokit"
gem "omniauth-rails_csrf_protection", "~> 1"
gem "omniauth-saml", "~> 2"
......@@ -103,4 +104,4 @@ group :test do
gem "simplecov", require: false
end
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
\ No newline at end of file
......@@ -425,6 +425,7 @@ GEM
rack (>= 1.2, < 4)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
observer (0.1.2)
octokit (8.1.0)
base64
faraday (>= 1, < 3)
......@@ -700,6 +701,7 @@ DEPENDENCIES
libretranslate
listen (~> 3.3)
mini_magick
observer (~> 0.1.2)
octokit
omniauth-rails_csrf_protection (~> 1)
omniauth-saml (~> 2)
......
......@@ -10,8 +10,10 @@ module Translatable
optional: true
has_many :translations,
class_name: base_class.to_s,
foreign_key: :original_id,
dependent: :nullify
foreign_key: :original_id
# has to be before_destroy because of the foreign key constraints
before_destroy :destroy_or_nullify_translations
scope :for_language, -> (language) { for_language_id(language.id) }
# The for_language_id scope can be used when you have the ID without needing to load the Language itself
......@@ -118,4 +120,16 @@ module Translatable
def translate_additional_data!(translation)
# Overridable method to handle custom cases
end
def destroy_or_nullify_translations
# Translatable is included in either Direct or Indirect Objects
# If object is direct we do not want to remove the translations
# If object is indirect we remove the translations
if is_direct_object?
translations.update_all(original_id: nil)
else
translations.destroy_all
end
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment