25 lines
662 B
Ruby
25 lines
662 B
Ruby
class Participant < ApplicationRecord
|
|
belongs_to :user
|
|
belongs_to :game
|
|
|
|
has_many :board_memberships, dependent: :destroy
|
|
has_many :boards, through: :board_memberships
|
|
has_many :board_posts, dependent: :destroy
|
|
|
|
# バリデーション
|
|
validates :user_id, uniqueness: {
|
|
scope: :game_id,
|
|
message: "既にこのゲームに参加しています"
|
|
}
|
|
|
|
validates :power, uniqueness: {
|
|
scope: :game_id,
|
|
message: "この国は既に選択されています"
|
|
}, allow_nil: true
|
|
|
|
validates :power, inclusion: {
|
|
in: %w[AUSTRIA ENGLAND FRANCE GERMANY ITALY RUSSIA TURKEY],
|
|
message: "無効な国です"
|
|
}, allow_nil: true
|
|
end
|