Permalink
Browse files

Merge pull request #7850 from senny/5920_postgres_adapter_table_with_…

…capital_letters

postgres, quote table names when fetching the primary key (#5920)
Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
  • Loading branch information...
rafaelfranca committed Oct 6, 2012
1 parent 9896729 commit de360ac565b5fea40f154f03fde3f74f0b4b31a8
View
@@ -1,17 +1,22 @@
## Rails 3.2.9 (unreleased)
-* `CollectionAssociation#count` returns 0 without querying if the
- parent record is new.
+* 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.
Before:
- person.pets
+ person.pets.count
# SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
# => 0
After:
- person.pets
+ person.pets.count
# fires without sql query
# => 0
@@ -999,7 +999,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 de360ac

Please sign in to comment.