Skip to content

Instantly share code, notes, and snippets.

@saturday
Last active June 18, 2016 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saturday/ffc89e4fd5ad7afe5a9c7971cc2dd080 to your computer and use it in GitHub Desktop.
Save saturday/ffc89e4fd5ad7afe5a9c7971cc2dd080 to your computer and use it in GitHub Desktop.
def self.save_recurring_tasks(tasks)
transaction = ActiveRecord::Base.transaction do
tasks.each_with_index do |task, index|
if index == 0
base_id = nil
end
task.base_task_id = base_id
task.save
if index == 0
base_id = task.id
end
end
end
transaction
end
@adam12
Copy link

adam12 commented Jun 18, 2016

transaction = ActiveRecord::Base.transaction do
  base_id = nil

  tasks.each do |task|
    task.base_task_id = base_id
    task.save

    base_id ||= task.id
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment