Skip to content

Commit 8fb196c

Browse files
Merge pull request #450 from zilverline/refactor/create-records
Use `insert_all` to insert multiple created records in projectors
2 parents fdea82a + 47a7254 commit 8fb196c

File tree

1 file changed

+1
-22
lines changed

1 file changed

+1
-22
lines changed

lib/sequent/core/persistors/active_record_persistor.rb

+1-22
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,7 @@ def create_record(record_class, values)
4545
end
4646

4747
def create_records(record_class, array_of_value_hashes)
48-
table = record_class.arel_table
49-
50-
query = array_of_value_hashes.map do |values|
51-
insert_manager = new_insert_manager
52-
insert_manager.into(table)
53-
insert_manager.insert(
54-
values.map do |key, value|
55-
convert_to_values(key, table, value)
56-
end,
57-
)
58-
insert_manager.to_sql
59-
end.join(';')
60-
61-
execute_sql(query)
48+
record_class.insert_all!(array_of_value_hashes, returning: false)
6249
end
6350

6451
def create_or_update_record(record_class, values, created_at = Time.now)
@@ -130,14 +117,6 @@ def commit
130117
def new_record(record_class, values)
131118
record_class.unscoped.new(values)
132119
end
133-
134-
def new_insert_manager
135-
Arel::InsertManager.new
136-
end
137-
138-
def convert_to_values(key, table, value)
139-
[table[key], table.type_cast_for_database(key, value)]
140-
end
141120
end
142121
end
143122
end

0 commit comments

Comments
 (0)