From 88bd4f77db3a4372c118a9faef613615db66bc52 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sat, 22 May 2021 14:32:38 -0400 Subject: Titles --- app/models/character.rb | 3 +++ app/models/chat_room.rb | 2 +- app/models/title.rb | 3 +++ app/models/title_award.rb | 6 ++++++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 app/models/title.rb create mode 100644 app/models/title_award.rb (limited to 'app/models') diff --git a/app/models/character.rb b/app/models/character.rb index 41dc951..73d2c4b 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -1,6 +1,9 @@ class Character < ApplicationRecord belongs_to :user belongs_to :activity, optional: true + has_many :title_awards + has_many :titles, through: :title_awards + belongs_to :active_title, class_name: "Title", optional: true has_one :hearth has_many :character_items has_many :learned_activities diff --git a/app/models/chat_room.rb b/app/models/chat_room.rb index 17e3f19..f1e9a24 100644 --- a/app/models/chat_room.rb +++ b/app/models/chat_room.rb @@ -14,7 +14,7 @@ class ChatRoom < ApplicationRecord } def self.accessible_to(user) - all.select { |x| x.accessible_to?(user) } + all.select { |x| x.accessible_to?(user) && x.gid != "achievement" } end def accessible_to?(user) diff --git a/app/models/title.rb b/app/models/title.rb new file mode 100644 index 0000000..c80a1d1 --- /dev/null +++ b/app/models/title.rb @@ -0,0 +1,3 @@ +class Title < ApplicationRecord + validates :gid, :name, presence: true +end diff --git a/app/models/title_award.rb b/app/models/title_award.rb new file mode 100644 index 0000000..ef74958 --- /dev/null +++ b/app/models/title_award.rb @@ -0,0 +1,6 @@ +class TitleAward < ApplicationRecord + belongs_to :title + belongs_to :character + + validates :character_id, uniqueness: { scope: :title_id } +end -- cgit v1.2.3