I have a Publication object and i’d like to insert...
# exposed
r
I have a Publication object and i’d like to insert a batch of them. Two options: 1. Insert only via the Entity
Copy code
for loop
  Publication.new { ... }
2. Insert via entity table
Copy code
Publication.table.batchInsert
1? 2? I’m not sure
s
One would think batchInsert would be appropriate for inserting a batch
b
well, there is not much difference. If you have Entity everywhere, then the first one. Also, if, after insertion, these Entities are used below (in a transaction), then there is no additional select in the case of the first option
r
Actually there is a little difference :
batchInsert
returns
List<ResultRow>
so this can help to notify if something was inserted or not. With a “manual” loop +
new
we need a some sort of counter
b
Copy code
sequnce { Entity.new {} }.count()