def apply_custom_fields_localize_diff(name)
      return if self._custom_field_localize_diff[name].empty?

      self.send(name).all.each do |record|
        updates = {}

        # puts "[apply_custom_fields_localize_diff] processing: record #{record._id} / #{self._custom_field_localize_diff[name].inspect}" # DEBUG
        self._custom_field_localize_diff[name].each do |changes|
          if changes[:localized]
            value = record.read_attribute(changes[:field].to_sym)
            updates[changes[:field]] = { Mongoid::Fields::I18n.locale.to_s => value }
          else
            # the other way around
            value = record.read_attribute(changes[:field].to_sym)
            next if value.nil?
            updates[changes[:field]] = value[Mongoid::Fields::I18n.locale.to_s]
          end
        end

        next if updates.empty?

        collection = self.send(name).collection
        collection.find(record.atomic_selector).update_one({ '$set' => updates })
      end
    end
def apply_custom_fields_localize_diff(name)
      return if self._custom_field_localize_diff[name].empty?

      self.send(name).all.each do |record|
        updates = {}

        # puts "[apply_custom_fields_localize_diff] processing: record #{record._id} / #{self._custom_field_localize_diff[name].inspect}" # DEBUG
        self._custom_field_localize_diff[name].each do |changes|
          if changes[:localized]
            value = record.read_attribute(changes[:field].to_sym)
            updates[changes[:field]] = { Mongoid::Fields::I18n.locale.to_s => value }
          else
            # the other way around
            value = record.read_attribute(changes[:field].to_sym)
            next if value.nil?
            updates[changes[:field]] = value[Mongoid::Fields::I18n.locale.to_s]
          end
        end

        next if updates.empty?

        collection = self.send(name).collection
        collection.find(record.atomic_selector).update_one({ '$set' => updates })
      end
    end
If the localized attribute has been changed in at least one of the custom fields,
 we have to upgrade all the records enhanced by custom_fields in order to make
 the values consistent with the mongoid localize option.

 Ex: post.attributes[:name] = 'Hello world' => post.attributes[:name] = { en: 'Hello world' }

 @param [ String, Symbol ] name The name of the relation.