ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

21 lines
448 B

  1. module MyDiscard
  2. extend ActiveSupport::Concern
  3. included { include Discard::Model }
  4. class_methods do
  5. def find_undiscard_or_create_by! attrs, &block
  6. record = with_discarded.find_by(attrs)
  7. if record&.discarded?
  8. record.undiscard!
  9. record.update_columns(created_at: record.reload.updated_at)
  10. end
  11. record or create!(attrs, &block)
  12. rescue ActiveRecord::RecordNotUnique
  13. retry
  14. end
  15. end
  16. end