Require has_internal_id to pass a init block.
This is useful since the current scheme allows us to freely delete any records in internal_ids. If the record is not there, it will get rebuild using the init block. We require passing in 'init for the time being and as long as its not expensive to do so. This makes the scheme a bit more robust. If at some point, this is expensive - we may choose to make this optional while losing the ability to recalculate the value on the fly. Closes #49609.
This commit is contained in:
parent
2ca8219a20
commit
90778e5d27
1 changed files with 4 additions and 0 deletions
|
@ -26,6 +26,10 @@ module AtomicInternalId
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def has_internal_id(column, scope:, init:, presence: true) # rubocop:disable Naming/PredicateName
|
def has_internal_id(column, scope:, init:, presence: true) # rubocop:disable Naming/PredicateName
|
||||||
|
# We require init here to retain the ability to recalculate in the absence of a
|
||||||
|
# InternaLId record (we may delete records in `internal_ids` for example).
|
||||||
|
raise "has_internal_id requires a init block, none given." unless init
|
||||||
|
|
||||||
before_validation :"ensure_#{scope}_#{column}!", on: :create
|
before_validation :"ensure_#{scope}_#{column}!", on: :create
|
||||||
validates column, presence: presence
|
validates column, presence: presence
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue