This commit is contained in:
2025-05-15 02:21:42 +09:00
parent 137c86bba7
commit 4cf3fc4d8c
12 changed files with 124 additions and 57 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ class NicoTagRelation < ApplicationRecord
belongs_to :tag, class_name: 'Tag', foreign_key: 'tag_id'
validates :nico_tag_id, presence: true
validates :tag_id, prosence: true
validates :tag_id, presence: true
validate :nico_tag_must_be_nico
+3
View File
@@ -1,4 +1,7 @@
class Post < ApplicationRecord
belongs_to :parent, class_name: 'Post', optional: true, foreign_key: 'parent_id'
belongs_to :user, foreign_key: ''
has_many :post_tags, dependent: :destroy
has_many :tags, through: :post_tags
has_many :user_post_views, dependent: :destroy
end
+7
View File
@@ -0,0 +1,7 @@
class PostTag < ApplicationRecord
belongs_to :post
belongs_to :tag
validates :post_id, presence: true
validates :tag_id, presence: true
end
+7
View File
@@ -0,0 +1,7 @@
class Setting < ApplicationRecord
belongs_to :user
validates :user_id, presence: true
validates :key, presence: true, length: { maximum: 255 }
validates :value, presence: true
end
+6 -1
View File
@@ -1,4 +1,9 @@
class Tag < ApplicationRecord
has_many :post_tags, dependent: :destroy
has_many :posts, through: :post_tags
has_many :tag_aliases, dependent: :destroy
has_many :wiki_pages, dependent: :nullify
validates :name, presence: true, length: { maximum: 255 }
validates :category, presence: true, inclusion: { in: categories.keys }
@@ -10,5 +15,5 @@ class Tag < ApplicationRecord
nico: 'nico',
meta: 'meta' }
scope :nico_tags, -> { where(category: :nico) }
scope :nico_tags, -> { where category: :nico }
end
+6
View File
@@ -0,0 +1,6 @@
class TagAlias < ApplicationRecord
belongs_to :tag
validates :tag_id, presence: true
validates :name, presence: true, length: { maximum: 255 }, uniqueness: true
end
+14
View File
@@ -9,4 +9,18 @@ class User < ApplicationRecord
has_many :posts
has_many :settings
has_many :ip_addresses
has_many :user_ips, dependent: :destroy
has_many :ip_addresses, through: :user_ips
has_many :user_post_views, dependent: :destroy
has_many :viewed_posts, through: :user_post_views, source: :post
has_many :created_wiki_pages, { class_name: 'WikiPage',
foreign_key: 'created_user_id',
dependent: :nullify }
has_many :updated_wiki_pages, { class_name: 'WikiPage',
foreign_key: 'updated_user_id',
dependent: :nullify }
def viewed? post
user_post_views.exists? post_id: post.id, viewed: true
end
end
+7
View File
@@ -0,0 +1,7 @@
class UserIp < ApplicationRecord
belongs_to :user
belongs_to :ip_address
validates :user_id, presence: true
validates :ip_address_id, presence: true
end
+7
View File
@@ -0,0 +1,7 @@
class UserPostView < ApplicationRecord
belongs_to :user
belongs_to :post
validates :user_id, presence: true
validates :post_id, presence: true
end
+11
View File
@@ -0,0 +1,11 @@
class WikiPage < ApplicationRecord
belongs_to :tag, optional: true
belongs_to :created_user, class_name: 'User', foreign_key: 'created_user_id'
belongs_to :updated_user, class_name: 'User', foreign_key: 'updated_user_id'
validates :title, presence: true, length: { maximum: 255 }, uniqueness: true
def gollum_path
"wiki/#{ title.parameterize }.md"
end
end