Flowdock
method

disable_referential_integrity

Importance_0
v6.1.3.1 - Show latest stable - 0 notes - Class: ReferentialIntegrity
disable_referential_integrity() public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb, line 7
        def disable_referential_integrity # :nodoc:
          original_exception = nil

          begin
            transaction(requires_new: true) do
              execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
            end
          rescue ActiveRecord::ActiveRecordError => e
            original_exception = e
          end

          begin
            yield
          rescue ActiveRecord::InvalidForeignKey => e
            warn WARNING: Rails was not able to disable referential integrity.This is most likely caused due to missing permissions.Rails needs superuser privileges to disable referential integrity.    cause: #{original_exception&.message}
            raise e
          end

          begin
            transaction(requires_new: true) do
              execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
            end
          rescue ActiveRecord::ActiveRecordError
          end
        end
Register or log in to add new notes.