Skip to content
This repository
Browse code

Fix a problem of translate_exception method in Japanese.

  • Loading branch information...
commit 2fe281323c8ccebc592d423b69b5b03ac9254b29 1 parent 777d539
Toshinori Kajihara authored May 20, 2012
10  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1336,11 +1336,15 @@ def postgresql_version
1336 1336
           @connection.server_version
1337 1337
         end
1338 1338
 
  1339
+        # See http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html
  1340
+        FOREIGN_KEY_VIOLATION = "23503"
  1341
+        UNIQUE_VIOLATION      = "23505"
  1342
+
1339 1343
         def translate_exception(exception, message)
1340  
-          case exception.message
1341  
-          when /duplicate key value violates unique constraint/
  1344
+          case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE)
  1345
+          when UNIQUE_VIOLATION
1342 1346
             RecordNotUnique.new(message, exception)
1343  
-          when /violates foreign key constraint/
  1347
+          when FOREIGN_KEY_VIOLATION
1344 1348
             InvalidForeignKey.new(message, exception)
1345 1349
           else
1346 1350
             super

0 notes on commit 2fe2813

Please sign in to comment.
Something went wrong with that request. Please try again.