Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/models/contest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ class Contest < ApplicationRecord
has_many :contest_relations, dependent: :destroy
has_many :registrants, through: :contest_relations, source: :user

has_many :contestant_records, -> { where(checked_in: true).where.not(started_at: nil) }, class_name: ContestRelation
has_many :contestant_records, -> { where(checked_in: true).where.not(started_at: nil) }, class_name: "ContestRelation"
has_many :contestants, through: :contestant_records, source: :user

has_many :contest_supervisors, dependent: :destroy
has_many :supervisors, through: :contest_supervisors, source: :user

has_many :group_associations, class_name: GroupContest, inverse_of: :contest, dependent: :destroy
has_many :group_associations, class_name: "GroupContest", inverse_of: :contest, dependent: :destroy
has_many :groups, through: :group_associations
has_many :group_members, -> { distinct }, through: :groups, source: :users

belongs_to :owner, class_name: :User
belongs_to :owner, class_name: "User"

validates :name, presence: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/contest_relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ContestRelation < ApplicationRecord
belongs_to :contest
has_many :contest_scores, dependent: :destroy
belongs_to :school
belongs_to :supervisor, class_name: :User
belongs_to :supervisor, class_name: "User"

scope :active, -> { where("started_at <= :now AND finish_at > :now", now: DateTime.now) }
scope :absent, -> { where(checked_in: false) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Evaluator < ApplicationRecord
include ActiveModel::ForbiddenAttributesProtection

has_many :problems
belongs_to :owner, class_name: :User
belongs_to :owner, class_name: "User"
belongs_to :language

validates :name, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/file_attachment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class FileAttachment < ApplicationRecord
include ActiveModel::ForbiddenAttributesProtection

belongs_to :owner, class_name: :User
belongs_to :owner, class_name: "User"

has_many :filelinks, dependent: :destroy

Expand Down
12 changes: 6 additions & 6 deletions app/models/group.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
class Group < ApplicationRecord
include ActiveModel::ForbiddenAttributesProtection

has_many :memberships, class_name: GroupMembership, dependent: :destroy
has_many :memberships, class_name: "GroupMembership", dependent: :destroy
has_many :members, through: :memberships
has_many :problem_set_associations, -> { includes(:problem_set).order("COALESCE(group_problem_sets.name,problem_sets.name)").references(:group_problem_sets, :problem_sets) }, class_name: GroupProblemSet, dependent: :destroy, inverse_of: :group
has_many :problem_set_associations, -> { includes(:problem_set).order("COALESCE(group_problem_sets.name,problem_sets.name)").references(:group_problem_sets, :problem_sets) }, class_name: "GroupProblemSet", dependent: :destroy, inverse_of: :group
has_many :problem_sets, through: :problem_set_associations
has_many :contest_associations, class_name: GroupContest, inverse_of: :group, dependent: :destroy
has_many :contest_associations, class_name: "GroupContest", inverse_of: :group, dependent: :destroy
has_many :contests, through: :contest_associations

belongs_to :owner, class_name: :User
belongs_to :owner, class_name: "User"

has_many :join_requests, -> { where(subject_type: "User", verb: "join") }, class_name: :Request, as: :target
has_many :join_requests, -> { where(subject_type: "User", verb: "join") }, class_name: "Request", as: :target
# , -> { where :subject_type => :users, :verb => :join }
# has_many :applicants, :through => :applications, :source => :subject, :source_type => 'User'
# def applicants
# self.join_requests.pending.subject
# end

has_many :invitations, -> { where(verb: "invite", target_type: "User") }, class_name: :Request, as: :subject
has_many :invitations, -> { where(verb: "invite", target_type: "User") }, class_name: "Request", as: :subject
# , -> { where :verb => :invite, :target_type => :users }
# has_many :invitees, :through => :invitations, :source => :target, :source_type => 'User', :conditions => { :status => Request::STATUS[:pending] } # TODO: expired_at condition

Expand Down
2 changes: 1 addition & 1 deletion app/models/group_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class GroupMembership < ApplicationRecord
include ActiveModel::ForbiddenAttributesProtection

belongs_to :group
belongs_to :member, class_name: :User
belongs_to :member, class_name: "User"
end
8 changes: 4 additions & 4 deletions app/models/item.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class Item < ApplicationRecord
belongs_to :product
belongs_to :owner, class_name: Entity
belongs_to :owner, class_name: "Entity"
belongs_to :organisation
belongs_to :sponsor, class_name: Entity
belongs_to :donator, class_name: Entity
belongs_to :holder, class_name: User
belongs_to :sponsor, class_name: "Entity"
belongs_to :donator, class_name: "Entity"
belongs_to :holder, class_name: "User"

has_many :item_histories

Expand Down
2 changes: 1 addition & 1 deletion app/models/item_history.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ItemHistory < ApplicationRecord
belongs_to :item
belongs_to :holder, class_name: User
belongs_to :holder, class_name: "User"

# active: is the action active? (set by user borrowing book, or staff accepting return - ie. verifiable action)
# action: enumeration
Expand Down
2 changes: 1 addition & 1 deletion app/models/language.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Language < ApplicationRecord
belongs_to :group, class_name: LanguageGroup
belongs_to :group, class_name: "LanguageGroup"

def source_filename
self[:source_filename] || "program"
Expand Down
2 changes: 1 addition & 1 deletion app/models/language_group.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class LanguageGroup < ApplicationRecord
has_many :languages, foreign_key: :group_id
belongs_to :current_language, class_name: Language
belongs_to :current_language, class_name: "Language"
end
10 changes: 5 additions & 5 deletions app/models/problem.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
class Problem < ApplicationRecord
include ActiveModel::ForbiddenAttributesProtection

has_many :problem_set_associations, class_name: ProblemSetProblem, inverse_of: :problem, dependent: :destroy
has_many :problem_set_associations, class_name: "ProblemSetProblem", inverse_of: :problem, dependent: :destroy
has_many :problem_sets, through: :problem_set_associations

has_many :test_sets, -> { rank(:problem_order) }, inverse_of: :problem, dependent: :destroy
has_many :prerequisite_sets, -> { where(prerequisite: true).rank(:problem_order) }, class_name: TestSet
has_many :prerequisite_sets, -> { where(prerequisite: true).rank(:problem_order) }, class_name: "TestSet"
has_many :test_cases, -> { rank(:problem_order) }, inverse_of: :problem, dependent: :destroy
has_many :sample_cases, -> { where(sample: true).rank(:problem_order) }, class_name: TestCase
has_many :sample_cases, -> { where(sample: true).rank(:problem_order) }, class_name: "TestCase"
has_many :submissions, dependent: :destroy
has_many :test_submissions, -> { where.not(classification: [Submission::CLASSIFICATION[:ranked], Submission::CLASSIFICATION[:unranked]]).order(:evaluation) }, class_name: Submission
has_many :test_submissions, -> { where.not(classification: [Submission::CLASSIFICATION[:ranked], Submission::CLASSIFICATION[:unranked]]).order(:evaluation) }, class_name: "Submission"

has_many :user_problem_relations, dependent: :destroy

belongs_to :owner, class_name: :User
belongs_to :owner, class_name: "User"
belongs_to :evaluator

has_many :contests, through: :problem_sets
Expand Down
6 changes: 3 additions & 3 deletions app/models/problem_set.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class ProblemSet < ApplicationRecord
include ActiveModel::ForbiddenAttributesProtection

has_many :problem_associations, -> { rank(:problem_set_order) }, class_name: ProblemSetProblem, inverse_of: :problem_set, dependent: :destroy
has_many :problem_associations, -> { rank(:problem_set_order) }, class_name: "ProblemSetProblem", inverse_of: :problem_set, dependent: :destroy
has_many :problems, through: :problem_associations
has_many :group_associations, class_name: GroupProblemSet, inverse_of: :problem_set, dependent: :destroy
has_many :group_associations, class_name: "GroupProblemSet", inverse_of: :problem_set, dependent: :destroy
has_many :groups, through: :group_associations
has_many :group_memberships, -> { distinct }, through: :groups, source: :memberships

has_many :contests
has_many :contest_relations, through: :contests, source: :contest_relations

belongs_to :owner, class_name: :User
belongs_to :owner, class_name: "User"

accepts_nested_attributes_for :problem_associations

Expand Down
4 changes: 2 additions & 2 deletions app/models/request.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class Request < ApplicationRecord
include ActiveModel::ForbiddenAttributesProtection

belongs_to :requester, class_name: :User # entity that initiated request
belongs_to :requester, class_name: "User" # entity that initiated request
belongs_to :subject, polymorphic: true # subject controlled by requester
# verb # action applying subject to target
belongs_to :target, polymorphic: true # target controlled by requestee
belongs_to :requestee, class_name: :User # entity with primary responsibility/right to accept this request
belongs_to :requestee, class_name: "User" # entity with primary responsibility/right to accept this request

STATUS = Enumeration.new 0 => :pending, 1 => :accepted, 2 => :rejected, 3 => :cancelled

Expand Down
4 changes: 2 additions & 2 deletions app/models/school.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class School < ApplicationRecord
has_many :users, dependent: :nullify

has_many :synonyms, class_name: School, as: :synonym
belongs_to :synonym, class_name: School
has_many :synonyms, class_name: "School", as: :synonym
belongs_to :synonym, class_name: "School"
end
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class User < ApplicationRecord
# NOTE: difference between groups and roles
# Groups are used to assign local permissions, eg. access to individual problems/problem sets
# Roles are used to assign global permissions, eg. access to problems on the whole site
has_many :memberships, class_name: :GroupMembership, foreign_key: :member_id, dependent: :destroy
has_many :memberships, class_name: "GroupMembership", foreign_key: :member_id, dependent: :destroy
has_many :user_problem_relations, dependent: :destroy
has_many :groups, through: :memberships
has_and_belongs_to_many :roles

# has_many :group_invitations, :class_name => :Request, :as => :target, :conditions => { :verb => 'invite', :subject_type => 'Group' }
has_many :requests, -> { where("requestee_id = target_id") }, class_name: Request, as: :target
has_many :requests, -> { where("requestee_id = target_id") }, class_name: "Request", as: :target
has_one :entity, as: :entity

belongs_to :school, counter_cache: true

has_many :contest_supervising, class_name: :ContestSupervisor, dependent: :destroy
has_many :contest_supervising, class_name: "ContestSupervisor", dependent: :destroy

# Scopes

Expand Down
2 changes: 1 addition & 1 deletion app/models/user_problem_relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class UserProblemRelation < ApplicationRecord
belongs_to :user
# caches the score of the best ranked submission and best submission a user scored for a problem
belongs_to :submission
belongs_to :ranked_submission, class_name: Submission
belongs_to :ranked_submission, class_name: "Submission"

validates_uniqueness_of :user_id, scope: :problem_id

Expand Down