From ed5959d8e0adffd9718570d212c3081b4d5934d2 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 31 Mar 2016 09:05:04 -0400 Subject: [PATCH] Added transaction to items --- app/models/qbo_item.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/qbo_item.rb b/app/models/qbo_item.rb index 1f5a3e4..9448e42 100644 --- a/app/models/qbo_item.rb +++ b/app/models/qbo_item.rb @@ -21,6 +21,7 @@ class QboItem < ActiveRecord::Base def self.update_all items = get_base.service.find_by(:type, "Service") +transaction do # Update the item table items.each { |item| qbo_item = QboItem.find_or_create_by(id: item.id) @@ -28,6 +29,7 @@ class QboItem < ActiveRecord::Base qbo_item.id = item.id qbo_item.save! } +end #remove deleted items where.not(items.map(&:id)).destroy_all