Skip to content

Commit

Permalink
Remove custom "distinct" scope, since it's provided by Rails, and Rai…
Browse files Browse the repository at this point in the history
…ls 4.1 forbids that name

The "distinct" method is available since Rails 4.0.0 [1] (and was
available as "uniq" since Rails 3.2.0 [2]), so we no longer need to
define our own "distinct" scope.

And as of Rails 4.1 it is forbidden to define a scope with a
conflicting name[3], so we have to remove our "distinct" scope.

[1] rails/rails@a1bb6c8
[2] rails/rails@562583c
[3] rails/rails#13450

Co-authored-by: Tom Levy <tomlevy93@gmail.com>
  • Loading branch information
bagedevimo and tom93 committed Mar 10, 2023
1 parent 48fc1a5 commit b911b8d
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 20 deletions.
3 changes: 0 additions & 3 deletions app/models/contest.rb
Expand Up @@ -43,9 +43,6 @@ def update_contest_scores # calculate contest scores again from scratch
end
end

# Scopes
scope :distinct, -> { select("distinct(contests.id), contests.*") }

def self.user_currently_in(user_id)
joins(:contest_relations).where(:contest_relations => { :user_id => user_id }).where("contest_relations.started_at <= :time AND contest_relations.finish_at > :time",{:time => DateTime.now})
end
Expand Down
3 changes: 0 additions & 3 deletions app/models/group.rb
Expand Up @@ -25,9 +25,6 @@ class Group < ActiveRecord::Base

validates :name, :presence => true, :uniqueness => { :case_sensitive => false }

# Scopes
scope :distinct, -> { select("distinct(groups.id), groups.*") }

VISIBILITY = Enumeration.new 0 => :public, 1 => :unlisted, 2 => :private
MEMBERSHIP = Enumeration.new 0 => [:open,'Membership is open to the public'],
1 => [:invitation,'Membership is by invitation or applying to join'],
Expand Down
1 change: 0 additions & 1 deletion app/models/problem.rb
Expand Up @@ -38,7 +38,6 @@ class Problem < ActiveRecord::Base
end

# Scopes
scope :distinct, -> { select("distinct(problems.id), problems.*") }

scope :score_by_user, ->(user_id) {
select("problems.*, (SELECT MAX(submissions.score) FROM submissions WHERE submissions.problem_id = problems.id AND submissions.user_id = #{user_id.to_i}) AS score")
Expand Down
3 changes: 0 additions & 3 deletions app/models/problem_set.rb
Expand Up @@ -16,9 +16,6 @@ class ProblemSet < ActiveRecord::Base

validates :name, :presence => true

# Scopes
scope :distinct, -> { select("distinct(problem_sets.id), problem_sets.*") }

def problems_with_scores_by_user(user_id)
problems.joins("LEFT OUTER JOIN user_problem_relations ON user_problem_relations.problem_id = problems.id AND user_problem_relations.user_id = #{user_id} LEFT OUTER JOIN submissions ON submissions.id = user_problem_relations.submission_id").select([:id, :name, :test_error_count, :test_warning_count, :test_status, {submissions: [:points, :maximum_points], problem_set_problems: :weighting}])
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/role.rb
@@ -1,9 +1,5 @@
class Role < ActiveRecord::Base

has_and_belongs_to_many :users

validates :name, :presence => true

scope :distinct, -> { select("distinct(roles.id), roles.*") }

end
3 changes: 0 additions & 3 deletions app/models/submission.rb
Expand Up @@ -86,9 +86,6 @@ def contests
@_mycontests ||= Contest.joins(:contest_relations, :problems).where(:contest_relations => {:user_id => user_id}, :problems => {:id => self.problem_id}).where("contest_relations.started_at <= ? AND contest_relations.finish_at > ?", self.created_at, self.created_at)
end

# scopes (lazy running SQL queries)
scope :distinct, -> { select("distinct(submissions.id), submissions.*") }

def self.by_user(user_id)
where("submissions.user_id IN (?)", user_id.to_s.split(','))
end
Expand Down
2 changes: 0 additions & 2 deletions app/models/test_case.rb
Expand Up @@ -10,8 +10,6 @@ class TestCase < ActiveRecord::Base
errors.add :output, "cannot be nil" if output.nil?
end

scope :distinct, -> { select("distinct(test_cases.id), test_cases.*") }

include RankedModel
ranks :problem_order, with_same: :problem_id

Expand Down
1 change: 0 additions & 1 deletion app/models/user.rb
Expand Up @@ -44,7 +44,6 @@ class User < ActiveRecord::Base

# Scopes

scope :distinct, -> { select("distinct(users.id), users.*") }
scope :num_solved, -> { select("users.*, (SELECT COUNT(DISTINCT problem_id) FROM user_problem_relations WHERE user_id = users.id AND ranked_score = 100) as num_solved") }

def self.find_for_authentication(conditions={})
Expand Down

0 comments on commit b911b8d

Please sign in to comment.