Skip to content

Commit

Permalink
Abstract table name
Browse files Browse the repository at this point in the history
Abstract table name
  • Loading branch information
Ladas committed Feb 1, 2018
1 parent 19e7b46 commit 02ec5d7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/models/manager_refresh/save_collection/saver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(inventory_collection)

# Private attrs
@model_class = inventory_collection.model_class
@table_name = @model_class.table_name
@primary_key = @model_class.primary_key
@arel_primary_key = @model_class.arel_attribute(@primary_key)
@unique_index_keys = inventory_collection.manager_ref_to_cols.map(&:to_sym)
Expand Down Expand Up @@ -75,7 +76,7 @@ def save_inventory_collection!

attr_reader :unique_index_keys, :unique_index_keys_to_s, :select_keys, :unique_db_primary_keys, :unique_db_indexes,
:primary_key, :arel_primary_key, :record_key_method, :pure_sql_records_fetching, :select_keys_indexes,
:batch_size, :batch_size_for_persisting, :model_class, :serializable_keys, :pg_types
:batch_size, :batch_size_for_persisting, :model_class, :serializable_keys, :pg_types, :table_name

def save!(association)
attributes_index = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def build_insert_query(all_attribute_keys, hashes)

# Make sure we don't send a primary_key for INSERT in any form, it could break PG sequencer
all_attribute_keys_array = all_attribute_keys.to_a - [primary_key.to_s, primary_key.to_sym]
table_name = inventory_collection.model_class.table_name
values = hashes.map do |hash|
"(#{all_attribute_keys_array.map { |x| quote(connection, hash[x], x) }.join(",")})"
end.join(",")
Expand Down Expand Up @@ -78,7 +77,6 @@ def build_update_query(all_attribute_keys, hashes)
# We want to ignore type and create timestamps when updating
all_attribute_keys_array = all_attribute_keys.to_a.delete_if { |x| %i(type created_at created_on).include?(x) }
all_attribute_keys_array << :id
table_name = inventory_collection.model_class.table_name

values = hashes.map! do |hash|
"(#{all_attribute_keys_array.map { |x| quote(connection, hash[x], x, true) }.join(",")})"
Expand Down

0 comments on commit 02ec5d7

Please sign in to comment.