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

20 lines
597 B

  1. class PostImplication < ApplicationRecord
  2. self.primary_key = :post_id, :parent_post_id
  3. belongs_to :post, inverse_of: :parent_post_implications
  4. belongs_to :parent_post, class_name: 'Post', inverse_of: :child_post_implications
  5. validates :post_id, presence: true, uniqueness: { scope: :parent_post_id }
  6. validates :parent_post_id, presence: true
  7. validate :parent_post_mustnt_be_itself
  8. private
  9. def parent_post_mustnt_be_itself
  10. if parent_post_id == post_id
  11. errors.add :parent_post_id, '親投稿に同じ投稿を設定することはできません.'
  12. end
  13. end
  14. end