ぼざクリタグ広場 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.
 
 
 
 
 
 

36 lines
1.0 KiB

  1. class PostVersion < ApplicationRecord
  2. before_update do
  3. raise ActiveRecord::ReadOnlyRecord, '版は更新できません.'
  4. end
  5. before_destroy do
  6. raise ActiveRecord::ReadOnlyRecord, '版は削除できません.'
  7. end
  8. belongs_to :post
  9. belongs_to :parent, class_name: 'Post', optional: true
  10. belongs_to :created_by_user, class_name: 'User', optional: true
  11. enum :event_type, create: 'create', update: 'update', discard: 'discard', restore: 'restore'
  12. validates :version_no, presence: true, numerically: { only_integer: true, greater_than: 0 }
  13. validates :event_type, presence: true, inclusion: { in: event_types.keys }
  14. validates :url, presence: true
  15. validate :validate_original_created_range
  16. scope :chronological, -> { order(:version_no, :id) }
  17. private
  18. def validate_original_created_range
  19. f = original_created_from
  20. b = original_created_before
  21. return if f.blank? || b.blank?
  22. if f >= b
  23. errors.add :original_created_before, 'オリジナルの作成日時の順番がをかしぃです.'
  24. end
  25. end
  26. end