Do transactions span Models?

T Tom Carvin 3 years 7 months ago
1 1 0

This sample is from the online docos

db = ::Rho::RHO.get_src_db('Model')
  db.start_transaction
  begin
  items.each do |item|
  # create hash of attribute/value pairs
  data = {
  :field1 => item['value1'],
  :field2 => item['value2']
  }
  # Creates a new Model object and saves it
  new_item = Model.create(data)
  end
  db.commit
  rescue
  db.rollback
  end

My question is, does that transaction span models such that I could create multiple new records of several dependent model types and, in the face of an eror, do a single rollback to revert them at once?

CONTACT
Can’t find what you’re looking for?