diff options
author | kennyj <kennyj@gmail.com> | 2012-05-20 01:38:14 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-05-20 01:38:14 +0900 |
commit | 2fe281323c8ccebc592d423b69b5b03ac9254b29 (patch) | |
tree | e0796df8b718bfb45e1d81a53c9579fc151c9668 /activerecord/lib/active_record | |
parent | 777d53901427ea183170c932d27eb43ce9fa5800 (diff) | |
download | rails-2fe281323c8ccebc592d423b69b5b03ac9254b29.tar.gz rails-2fe281323c8ccebc592d423b69b5b03ac9254b29.tar.bz2 rails-2fe281323c8ccebc592d423b69b5b03ac9254b29.zip |
Fix a problem of translate_exception method in Japanese.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 14bc95abfe..15c3d7be36 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1336,11 +1336,15 @@ module ActiveRecord @connection.server_version end + # See http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html + FOREIGN_KEY_VIOLATION = "23503" + UNIQUE_VIOLATION = "23505" + def translate_exception(exception, message) - case exception.message - when /duplicate key value violates unique constraint/ + case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE) + when UNIQUE_VIOLATION RecordNotUnique.new(message, exception) - when /violates foreign key constraint/ + when FOREIGN_KEY_VIOLATION InvalidForeignKey.new(message, exception) else super |