Answers.Body: <p>You could use a task within your plugin for better performance when looping through your records.</p>
  
  <p>Check the <a href="https://craftcms.com/classreference/services/TasksService" rel="nofollow">TasksService</a> docs and also <a href="https://github.com/pixelandtonic/PowerNap/" rel="nofollow">PowerNap</a>, an example plugin that uses a task. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-18T09:14:38.453Z
Answers.LastActivityDate: 2016-05-18T09:14:38.453Z
Answers.UserDisplayName: Luke Pearce
Body: <p>I would like to be able to save multiple records at once. What is the best way of doing this? I can of course iterate over my records and use the save function for each one. However, this is not very good for performance. The other option I can think of is to create my own database query using the insertAll command. This would be better for performance.</p>
  
  <p>Is there any built in function to batch save multiple records at once or is the insertAll alternative the way to go?</p>
  
  <p>Thanks for your time. </p>
  
Tags: <database><records>
Title: Save multiple records at once
ThreadText: # Save multiple records at once
  
  (Asked by: username_0 on 2016-05-18)
  
  I would like to be able to save multiple records at once. What is the best way of doing this? I can of course iterate over my records and use the save function for each one. However, this is not very good for performance. The other option I can think of is to create my own database query using the insertAll command. This would be better for performance.
  
  Is there any built in function to batch save multiple records at once or is the insertAll alternative the way to go?
  
  Thanks for your time.
  
  **Tags:** database, records
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-18. Score: 2
  
  You could use a task within your plugin for better performance when looping through your records.
  
  Check the [TasksService](https://craftcms.com/classreference/services/TasksService) docs and also [PowerNap](https://github.com/pixelandtonic/PowerNap/), an example plugin that uses a task.
  
  
  ---
  
  