diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-01-15 20:52:36 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-01-15 20:52:36 +0900 |
commit | 89653edaf6845d50cc5ac6bc19815e581454ce77 (patch) | |
tree | 8dcb1acb94d91efd0d96e75b3b1bc3f13d9f5476 /activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb | |
parent | b2874aec105c277b6008cb8d73ffd106a12b444b (diff) | |
download | rails-89653edaf6845d50cc5ac6bc19815e581454ce77.tar.gz rails-89653edaf6845d50cc5ac6bc19815e581454ce77.tar.bz2 rails-89653edaf6845d50cc5ac6bc19815e581454ce77.zip |
`sql_for_insert` returns values for passing to `exec_insert`
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index 11a151edd5..6c15facf3b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -72,16 +72,6 @@ module ActiveRecord end end - # Executes an INSERT query and returns the new record's ID - def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) # :nodoc: - unless pk - # Extract the table from the insert sql. Yuck. - table_ref = extract_table_ref_from_insert_sql(sql) - pk = primary_key(table_ref) if table_ref - end - super - end - # The internal PostgreSQL identifier of the money data type. MONEY_COLUMN_TYPE_OID = 790 #:nodoc: # The internal PostgreSQL identifier of the BYTEA data type. @@ -162,12 +152,18 @@ module ActiveRecord end alias :exec_update :exec_delete - def sql_for_insert(sql, pk, id_value, sequence_name, binds) + def sql_for_insert(sql, pk, id_value, sequence_name, binds) # :nodoc: + unless pk + # Extract the table from the insert sql. Yuck. + table_ref = extract_table_ref_from_insert_sql(sql) + pk = primary_key(table_ref) if table_ref + end + if pk && use_insert_returning? sql = "#{sql} RETURNING #{quote_column_name(pk)}" end - [sql, binds] + super end def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) |