Sha256: ebaa8ee23ca990719855dc8177eb441ee1102e46b90d2cb68748818b95aacb3f

Contents?: true

Size: 1.2 KB

Versions: 14

Compression:

Stored size: 1.2 KB

Contents

module HandleParanoiaDestroyedInBelongsToAssociation
  def handle_dependency
    return unless load_target

    case options[:dependent]
    when :destroy
      target.destroy
      if target.respond_to?(:paranoia_destroyed?)
        raise ActiveRecord::Rollback unless target.paranoia_destroyed?
      else
        raise ActiveRecord::Rollback unless target.destroyed?
      end
    else
      target.send(options[:dependent])
    end
  end
end

module HandleParanoiaDestroyedInHasOneAssociation
  def delete(method = options[:dependent])
    if load_target
      case method
      when :delete
        target.delete
      when :destroy
        target.destroyed_by_association = reflection
        target.destroy
        if target.respond_to?(:paranoia_destroyed?)
          throw(:abort) unless target.paranoia_destroyed?
        else
          throw(:abort) unless target.destroyed?
        end
      when :nullify
        target.update_columns(reflection.foreign_key => nil) if target.persisted?
      end
    end
  end
end

ActiveRecord::Associations::BelongsToAssociation.prepend HandleParanoiaDestroyedInBelongsToAssociation
ActiveRecord::Associations::HasOneAssociation.prepend HandleParanoiaDestroyedInHasOneAssociation

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
paranoia-3.0.1 lib/paranoia/active_record_5_2.rb
paranoia-3.0.0 lib/paranoia/active_record_5_2.rb
paranoia-2.6.4 lib/paranoia/active_record_5_2.rb
paranoia-2.6.3 lib/paranoia/active_record_5_2.rb
paranoia-2.6.2 lib/paranoia/active_record_5_2.rb
paranoia-2.6.1 lib/paranoia/active_record_5_2.rb
paranoia-2.6.0 lib/paranoia/active_record_5_2.rb
paranoia-2.5.3 lib/paranoia/active_record_5_2.rb
paranoia-2.5.2 lib/paranoia/active_record_5_2.rb
paranoia-2.5.1 lib/paranoia/active_record_5_2.rb
paranoia-2.5.0 lib/paranoia/active_record_5_2.rb
paranoia-2.4.3 lib/paranoia/active_record_5_2.rb
paranoia-2.4.2 lib/paranoia/active_record_5_2.rb
paranoia-2.4.1 lib/paranoia/active_record_5_2.rb