diff --git a/lib/uuidable/active_record.rb b/lib/uuidable/active_record.rb index b09203a..5e9ea9f 100644 --- a/lib/uuidable/active_record.rb +++ b/lib/uuidable/active_record.rb @@ -33,7 +33,11 @@ def uuidable(as_param: true) # rubocop:disable Metrics/AbcSize, Metrics/Cyclomat end end - after_initialize { self.uuid = Uuidable.generate_uuid if attributes.keys.include?('uuid') && uuid.blank? } + after_initialize do + self.uuid = Uuidable.generate_uuid if attributes.keys.include?('uuid') && uuid.blank? + self.uuid__old = uuid if respond_to?(:uuid__old) + end + validates :uuid, presence: true, uniqueness: true, if: :uuid_changed? if as_param