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

39 lines
1.1 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',
  12. update: 'update',
  13. discard: 'discard',
  14. restore: 'restore' }, prefix: true, validate: true
  15. validates :version_no, presence: true, numericality: { only_integer: true, greater_than: 0 }
  16. validates :event_type, presence: true, inclusion: { in: event_types.keys }
  17. validates :url, presence: true
  18. validate :validate_original_created_range
  19. scope :chronological, -> { order(:version_no, :id) }
  20. private
  21. def validate_original_created_range
  22. f = original_created_from
  23. b = original_created_before
  24. return if f.blank? || b.blank?
  25. if f >= b
  26. errors.add :original_created_before, 'オリジナルの作成日時の順番がをかしぃです.'
  27. end
  28. end
  29. end