diff options
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 18b499904e..e77ae93c21 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -941,6 +941,17 @@ module ActiveRecord end end + def translate_exception(exception, message) + case exception.message + when /duplicate key value violates unique constraint/ + RecordNotUnique.new(message, exception) + when /violates foreign key constraint/ + InvalidForeignKey.new(message, exception) + else + super + end + end + private # The internal PostgreSQL identifier of the money data type. MONEY_COLUMN_TYPE_OID = 790 #:nodoc: |