Class: ActiveRecord::InsertAll::Builder
- Defined in:
- activerecord/lib/active_record/insert_all.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #conflict_target ⇒ Object
-
#initialize(insert_all) ⇒ Builder
constructor
A new instance of Builder.
- #into ⇒ Object
- #returning ⇒ Object
- #updatable_columns ⇒ Object
- #values_list ⇒ Object
Constructor Details
#initialize(insert_all) ⇒ Builder
Returns a new instance of Builder.
120 121 122 |
# File 'activerecord/lib/active_record/insert_all.rb', line 120 def initialize(insert_all) @insert_all, @model, @connection = insert_all, insert_all.model, insert_all.connection end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model
116 117 118 |
# File 'activerecord/lib/active_record/insert_all.rb', line 116 def model @model end |
Instance Method Details
#conflict_target ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'activerecord/lib/active_record/insert_all.rb', line 142 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 |
#into ⇒ Object
124 125 126 |
# File 'activerecord/lib/active_record/insert_all.rb', line 124 def into "INTO #{model.quoted_table_name}(#{columns_list})" end |
#returning ⇒ Object
138 139 140 |
# File 'activerecord/lib/active_record/insert_all.rb', line 138 def returning format_columns(insert_all.returning) if insert_all.returning end |
#updatable_columns ⇒ Object
152 153 154 |
# File 'activerecord/lib/active_record/insert_all.rb', line 152 def updatable_columns quote_columns(insert_all.updatable_columns) end |
#values_list ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'activerecord/lib/active_record/insert_all.rb', line 128 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 Arel::InsertManager.new.create_values_list(values_list).to_sql end |