The below code deletes all the task users and inserts the new task users
by getting the ids from the UI.
I have two questions:
-
Is there any way to delete all the records in a single statement.
If we put task_users = [], generating the delete statement for every
record -
Is there any way to do the batch insert? The below code generates
more insert statement@task = Task.find(params[:task_id])
task_users = []
params[:ids].split(", ").each do |court_user_id|
task_users << TaskUser.new(:court_user_id => court_user_id)
endTask.transaction do
@task.task_users = task_users
@saved = @task.save
end