     (delete-transaction-items-by-transaction-id storage transaction-id)
     (delete-transaction storage transaction-id)
     (update-affected-balances storage preceding-items)))
-
-(defn reload
-  "Returns an updated copy of the transaction"
-  [storage-spec transaction]
-  (find-by-id storage-spec (:id transaction)))

        validated (validate Transaction transaction)]
    (if (validation/has-error? validated)
      validated
      (let [items-with-balances (calculate-balances-and-indexes storage
                                                                (:transaction-date validated)
                                                                (:items validated))
            _ (process-dereferenced-accounts storage validated) ; this relies on old values still being in the database
            _ (update-affected-balances storage
                                        items-with-balances
                                        (:transaction-date validated))
            processed-items (process-item-updates storage items-with-balances)]
        (assoc validated [:items] processed-items)))))

(defn- get-preceding-items
  "Returns the items that precede each item in the

       (map before-save-item)
       (mapv #(update-item storage %))))

(defn- dereferenced-accounts
  "Given an existing transaction and an update of the
  same transaction, returns the IDs of the accounts
  that were referenced in the original but are not
  referenced now"
  [existing updated]
  (apply difference (map #(->> (:items %)
                               (map :account-id)
                               (into #{}))
                         [existing updated])))

(defn reload
  "Returns an updated copy of the transaction"
  [storage-spec transaction]
  (find-by-id storage-spec (:id transaction)))

(defn update
  "Updates the specified transaction"
