diff --git a/lib/active_record/connection_adapters/odbc_adapter.rb b/lib/active_record/connection_adapters/odbc_adapter.rb index d643618..26dcc3b 100644 --- a/lib/active_record/connection_adapters/odbc_adapter.rb +++ b/lib/active_record/connection_adapters/odbc_adapter.rb @@ -146,6 +146,15 @@ def new_column(name, default, sql_type_metadata, null, native_type = nil) ::ODBCAdapter::Column.new(name, default, sql_type_metadata, null, native_type) end + #Snowflake doesn't have a mechanism to return the primary key on inserts, it needs prefetched + def prefetch_primary_key?(table_name = nil) + true + end + + def next_sequence_value(table_name = nil) + exec_query("SELECT #{table_name}.NEXTVAL as new_id").first["new_id"] + end + protected #Snowflake ODBC Adapter specific diff --git a/lib/odbc_adapter/concerns/insert_attribute_stripper.rb b/lib/odbc_adapter/concerns/insert_attribute_stripper.rb index 35dce2a..556526d 100644 --- a/lib/odbc_adapter/concerns/insert_attribute_stripper.rb +++ b/lib/odbc_adapter/concerns/insert_attribute_stripper.rb @@ -1,7 +1,6 @@ module ODBCAdapter module InsertAttributeStripper extend ActiveSupport::Concern - include EasyIdentified included do alias_method :pre_insert_attribute_stripper_save, :save @@ -29,11 +28,11 @@ def save_internal(base_function, **options, &block) self[column.name] = nil end end - if stripped_attributes.any? then generate_id end else stripped_attributes = {} end first_call_result = base_function.call(**options, &block) + return false if first_call_result == false if stripped_attributes.any? restore_stripped_attributes(stripped_attributes) return base_function.call(**options, &block)