2020-03-25 10:16:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# SuperClass for all app models.
|
|
|
|
# This is a single spot to configure app-wide model behavior.
|
|
|
|
class ApplicationRecord < ActiveRecord::Base
|
|
|
|
self.abstract_class = true
|
2023-01-09 17:36:11 +01:00
|
|
|
|
|
|
|
# Update attributes with validation context.
|
|
|
|
# In Rails you can provide a context while you save, for example: `.save(:step1)`, but no way to
|
|
|
|
# provide a context while you update. This method just adds the way to update with validation
|
|
|
|
# context.
|
|
|
|
#
|
|
|
|
# @param attributes [Hash] attributes to assign
|
|
|
|
# @param context [*] validation context
|
|
|
|
def update_with_context(attributes, context)
|
|
|
|
with_transaction_returning_status do
|
|
|
|
assign_attributes(attributes)
|
2023-02-24 17:26:55 +01:00
|
|
|
save(**{ context: context })
|
2023-01-09 17:36:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|