Permalink
Browse files

PostgreSQL, quote table names when fetching the primary key. Closes #…

  • Loading branch information...
1 parent a8c8a08 commit 16e4a53b78aacc78712ff6ad4aa2da3a69faff5c @senny senny committed with senny Oct 4, 2012
@@ -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.
@@ -314,7 +314,7 @@ def primary_key(table)
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
@@ -14,6 +14,10 @@ def test_primary_key
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)')

0 comments on commit 16e4a53

Please sign in to comment.