From cbb65de1a60f1263cab05627ab99c9f5e246cd5c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 11 Apr 2011 10:37:23 -0700 Subject: always look up pk and sequence unless both are provided --- .../active_record/connection_adapters/postgresql_adapter.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index a90e9a4b71..617d131c40 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -435,7 +435,11 @@ module ActiveRecord # Extract the table from the insert sql. Yuck. table = sql.split(" ", 4)[2].gsub('"', '') - pk, sequence_name = *pk_and_sequence_for(table) unless pk + # If neither pk nor sequence name is given, look them up. + unless pk || sequence_name + pk, sequence_name = *pk_and_sequence_for(table) + end + if pk id = select_value("#{sql} RETURNING #{quote_column_name(pk)}") return id @@ -443,11 +447,6 @@ module ActiveRecord super - # If neither pk nor sequence name is given, look them up. - unless pk || sequence_name - pk, sequence_name = *pk_and_sequence_for(table) - end - # If a pk is given, fallback to default sequence name. # Don't fetch last insert id for a table without a pk. if pk && sequence_name ||= default_sequence_name(table, pk) -- cgit v1.2.3