Modify model associations to map to new schema

This commit is contained in:
Thor77 2018-11-18 14:12:43 +01:00
parent c573fd9edd
commit 65abada8b2
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
5 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class Group < ApplicationRecord class Group < ApplicationRecord
belongs_to :matches belongs_to :stage
belongs_to :teams has_many :matches, dependent: :destroy
has_many :group_scores, dependent: :destroy
end end

View File

@ -2,4 +2,5 @@
class GroupScore < ApplicationRecord class GroupScore < ApplicationRecord
belongs_to :team belongs_to :team
belongs_to :group
end end

View File

@ -1,4 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class Match < ApplicationRecord class Match < ApplicationRecord
belongs_to :stage
belongs_to :group
has_many :scores, dependent: :destroy
end end

View File

@ -2,6 +2,6 @@
class Team < ApplicationRecord class Team < ApplicationRecord
belongs_to :tournament belongs_to :tournament
has_many :group_scores, dependent: :destroy
has_one :group_score, dependent: :destroy has_many :scores, dependent: :destroy
end end

View File

@ -3,12 +3,13 @@
require 'securerandom' require 'securerandom'
class Tournament < ApplicationRecord class Tournament < ApplicationRecord
belongs_to :user
has_many :teams, dependent: :destroy
has_many :stages, dependent: :destroy
validates :name, presence: true validates :name, presence: true
validates :code, presence: true, uniqueness: true validates :code, presence: true, uniqueness: true
has_many :teams, dependent: :destroy
belongs_to :user
alias_attribute :owner, :user alias_attribute :owner, :user
after_initialize do |tournament| after_initialize do |tournament|