@@ -65,14 +65,16 @@ def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil)
65
65
sql , binds = sql_for_insert ( sql , pk , nil , sequence_name , binds )
66
66
67
67
exec_query ( sql , name , binds ) . tap do |result |
68
- @_returned_attributes = result . first . to_hash
68
+ if @_returning_attributes . present?
69
+ @_returned_attributes = result . first . to_hash
70
+ end
69
71
end
70
72
end
71
73
72
74
def update ( arel , name = nil , binds = [ ] )
73
75
sql , binds = to_sql_and_binds ( arel , binds )
74
76
75
- if @_returning_attributes && ! @_returning_attributes . empty ?
77
+ if @_returning_attributes . present ?
76
78
sql = "#{ sql } RETURNING #{ @_returning_attributes . map { |column | quote_column_name ( column ) } . join ( ', ' ) } "
77
79
end
78
80
@@ -95,7 +97,11 @@ def sql_for_insert(sql, pk, id_value, sequence_name, binds)
95
97
end
96
98
97
99
if pk = suppress_composite_primary_key ( pk )
98
- sql = "#{ sql } RETURNING #{ [ pk , @_returning_attributes ] . flatten . map { |column | quote_column_name ( column ) } . join ( ', ' ) } "
100
+ sql = if @_returning_attributes . present?
101
+ "#{ sql } RETURNING #{ [ pk , @_returning_attributes ] . flatten . map { |column | quote_column_name ( column ) } . join ( ', ' ) } "
102
+ else
103
+ "#{ sql } RETURNING #{ quote_column_name ( pk ) } "
104
+ end
99
105
end
100
106
101
107
super
@@ -120,7 +126,7 @@ def execute_and_clear(sql, name, binds, prepare: false)
120
126
result = exec_cache ( sql , name , binds )
121
127
end
122
128
123
- if @_returning_attributes && ! @_returning_attributes . empty ?
129
+ if @_returning_attributes . present ?
124
130
@_returned_attributes = result . to_a . first
125
131
end
126
132
0 commit comments