Class: ActiveRecord::InsertAll::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/insert_all.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(insert_all) ⇒ Builder

Returns a new instance of Builder.



118
119
120
# File 'lib/active_record/insert_all.rb', line 118

def initialize(insert_all)
  @insert_all, @model, @connection = insert_all, insert_all.model, insert_all.connection
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



114
115
116
# File 'lib/active_record/insert_all.rb', line 114

def model
  @model
end

Instance Method Details

#conflict_targetObject



140
141
142
143
144
145
146
147
148
# File 'lib/active_record/insert_all.rb', line 140

def conflict_target
  if index = insert_all.unique_by
    sql = +"(#{format_columns(index.columns)})"
    sql << " WHERE #{index.where}" if index.where
    sql
  elsif update_duplicates?
    "(#{format_columns(insert_all.primary_keys)})"
  end
end

#intoObject



122
123
124
# File 'lib/active_record/insert_all.rb', line 122

def into
  "INTO #{model.quoted_table_name} (#{columns_list})"
end

#returningObject



136
137
138
# File 'lib/active_record/insert_all.rb', line 136

def returning
  format_columns(insert_all.returning) if insert_all.returning
end

#updatable_columnsObject



150
151
152
# File 'lib/active_record/insert_all.rb', line 150

def updatable_columns
  quote_columns(insert_all.updatable_columns)
end

#values_listObject



126
127
128
129
130
131
132
133
134
# File 'lib/active_record/insert_all.rb', line 126

def values_list
  types = extract_types_from_columns_on(model.table_name, keys: keys)

  values_list = insert_all.map_key_with_value do |key, value|
    connection.with_yaml_fallback(types[key].serialize(value))
  end

  connection.visitor.compile(Arel::Nodes::ValuesList.new(values_list))
end