diff options
author | Yves Senn <yves.senn@gmail.com> | 2012-10-04 21:57:44 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@garaio.com> | 2012-10-05 08:54:38 +0200 |
commit | 16e4a53b78aacc78712ff6ad4aa2da3a69faff5c (patch) | |
tree | e2d4046a87fb41ba505a1722ed0df7786eb75ca0 | |
parent | a8c8a08f1ae7099f750058ef3e168810e5ad47d8 (diff) | |
download | rails-16e4a53b78aacc78712ff6ad4aa2da3a69faff5c.tar.gz rails-16e4a53b78aacc78712ff6ad4aa2da3a69faff5c.tar.bz2 rails-16e4a53b78aacc78712ff6ad4aa2da3a69faff5c.zip |
PostgreSQL, quote table names when fetching the primary key. Closes #5920
3 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 714263faea..ba292e7f0e 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* The postgres adapter now supports tables with capital letters. + Fix #5920 + + *Yves Senn* + * `CollectionAssociation#count` returns `0` without querying if the parent record is not persisted. diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 8a073bf878..2264595751 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -314,7 +314,7 @@ module ActiveRecord INNER JOIN pg_depend dep ON attr.attrelid = dep.refobjid AND attr.attnum = dep.refobjsubid INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1] WHERE cons.contype = 'p' - AND dep.refobjid = '#{table}'::regclass + AND dep.refobjid = '#{quote_table_name(table)}'::regclass end_sql row && row.first diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index 92e31a3e44..f1362dd15f 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -14,6 +14,10 @@ module ActiveRecord assert_equal 'id', @connection.primary_key('ex') end + def test_primary_key_works_tables_containing_capital_letters + assert_equal 'id', @connection.primary_key('CamelCase') + end + def test_non_standard_primary_key @connection.exec_query('drop table if exists ex') @connection.exec_query('create table ex(data character varying(255) primary key)') |