ニジラー管理(#247) (#275)
#247 #247 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #275
This commit was merged in pull request #275.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
class Deerjikist < ApplicationRecord
|
||||
self.primary_key = :platform, :code
|
||||
|
||||
belongs_to :tag
|
||||
|
||||
validates :platform, presence: true
|
||||
validates :code, presence: true
|
||||
validates :tag_id, presence: true
|
||||
|
||||
validate :tag_must_be_deerjikist
|
||||
|
||||
enum :platform, nico: 'nico', youtube: 'youtube'
|
||||
|
||||
private
|
||||
|
||||
def tag_must_be_deerjikist
|
||||
if tag && !(tag.deerjikist?)
|
||||
errors.add :tag, 'タグはニジラー・カテゴリである必要があります.'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -24,6 +24,8 @@ class Tag < ApplicationRecord
|
||||
|
||||
has_many :tag_similarities, dependent: :delete_all
|
||||
|
||||
has_many :deerjikists, dependent: :delete_all
|
||||
|
||||
belongs_to :tag_name
|
||||
delegate :wiki_page, to: :tag_name
|
||||
|
||||
@@ -42,6 +44,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
validate :nico_tag_name_must_start_with_nico
|
||||
validate :tag_name_must_be_canonical
|
||||
validate :category_must_be_deerjikist_with_deerjikists
|
||||
|
||||
scope :nico_tags, -> { where(category: :nico) }
|
||||
|
||||
@@ -149,4 +152,10 @@ class Tag < ApplicationRecord
|
||||
errors.add :tag_name, 'tag_names へは実体を示す必要があります.'
|
||||
end
|
||||
end
|
||||
|
||||
def category_must_be_deerjikist_with_deerjikists
|
||||
if !(deerjikist?) && deerjikists.exists?
|
||||
errors.add :category, 'ニジラーと紐づいてゐるタグはニジラー・カテゴリである必要があります.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user