dceed1caa1
Merge remote-tracking branch 'origin/main' into feature/046 #46 #46 #46 #46 #46 #46 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #339
20 lines
597 B
Ruby
20 lines
597 B
Ruby
class PostImplication < ApplicationRecord
|
|
self.primary_key = :post_id, :parent_post_id
|
|
|
|
belongs_to :post, inverse_of: :parent_post_implications
|
|
belongs_to :parent_post, class_name: 'Post', inverse_of: :child_post_implications
|
|
|
|
validates :post_id, presence: true, uniqueness: { scope: :parent_post_id }
|
|
validates :parent_post_id, presence: true
|
|
|
|
validate :parent_post_mustnt_be_itself
|
|
|
|
private
|
|
|
|
def parent_post_mustnt_be_itself
|
|
if parent_post_id == post_id
|
|
errors.add :parent_post_id, '親投稿に同じ投稿を設定することはできません.'
|
|
end
|
|
end
|
|
end
|