From 302b6f3f73731c8daa108f9c40d7cf41463898d8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 11 Apr 2011 10:31:13 -0700 Subject: [PATCH] pg does not know the insert_id in advance, so super will never return true --- .../connection_adapters/postgresql_adapter.rb | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index a0be143c8e..a90e9a4b71 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -441,20 +441,17 @@ def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) return id end - # Otherwise, insert then grab last_insert_id. - if insert_id = super - insert_id - else - # If neither pk nor sequence name is given, look them up. - unless pk || sequence_name - pk, sequence_name = *pk_and_sequence_for(table) - end + super - # 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) - last_insert_id(sequence_name) - end + # 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) + last_insert_id(sequence_name) end end alias :create :insert