#2 ぼちぼち
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
class IpAddress < ApplicationRecord
|
||||
validates :ip_address, presence: true, length: { maximum: 16 }
|
||||
validates :banned, inclusion: { in: [true, false] }
|
||||
|
||||
has_many :users
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
class NicoTagRelation < ApplicationRecord
|
||||
belongs_to :nico_tag, class_name: 'Tag', foreign_key: 'nico_tag_id'
|
||||
belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id'
|
||||
|
||||
validates :nico_tag_id, presence: true
|
||||
validates :tag_id, prosence: true
|
||||
|
||||
validate :nico_tag_must_be_nico
|
||||
|
||||
private
|
||||
|
||||
def nico_tag_must_be_nico
|
||||
if nico_tag && nico_tag.category != :nico
|
||||
errors.add :nico_tag_id, 'タグのカテゴリがニコニコである必要があります.'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,2 +1,4 @@
|
||||
class Post < ApplicationRecord
|
||||
belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id'
|
||||
belongs_to :user, foreign_key: ''
|
||||
end
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class Tag < ApplicationRecord
|
||||
validates :name, presence: true, length: { maximum: 255 }
|
||||
validates :category, presence: true, inclusion: { in: categories.keys }
|
||||
|
||||
enum category: { deerjikist: 'deerjikist',
|
||||
meme: 'meme',
|
||||
character: 'character',
|
||||
general: 'general',
|
||||
material: 'material',
|
||||
nico: 'nico',
|
||||
meta: 'meta' }
|
||||
|
||||
scope :nico_tags, -> { where(category: :nico) }
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class User < ApplicationRecord
|
||||
validates :name, length: { maximum: 255 }
|
||||
validates :inheritance_code, presence: true, length: { maximum: 64 }
|
||||
validates :role, presence: true, inclusion: { in: roles.keys }
|
||||
validates :banned, inclusion: { in: [true, false] }
|
||||
|
||||
enum role: { guest: 'guest', member: 'member', admin: 'admin' }
|
||||
|
||||
has_many :posts
|
||||
has_many :settings
|
||||
has_many :ip_addresses
|
||||
end
|
||||
Reference in New Issue
Block a user