mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +00:00
Fix more scopes due to AR upgrades
This commit is contained in:
parent
9a6db89139
commit
46fab90cf4
6 changed files with 8 additions and 10 deletions
|
@ -43,7 +43,7 @@ class Category < ActiveRecord::Base
|
|||
scope :nospecial, -> { where.not(name: 'Special') }
|
||||
scope :newest, -> { includes(:articles).order("articles.created_at DESC") }
|
||||
# scope :page, lambda { |page| {:limit => "#{(page-1)*PER_PAGE}, #{(page-1)*PER_PAGE+PER_PAGE}"} }
|
||||
scope :of_user, -> (user) { where("articles.user_id", user.id).includes(:articles) }
|
||||
scope :of_user, -> (user) { where(articles: {user: user}).includes(:articles) }
|
||||
|
||||
has_many :articles, -> { order("created_at DESC") }
|
||||
has_many :issues, -> { order("created_at DESC") }
|
||||
|
|
|
@ -40,8 +40,6 @@ class Contest < ActiveRecord::Base
|
|||
TYPE_LEAGUE = 1
|
||||
TYPE_BRACKET = 2
|
||||
|
||||
#attr_protected :id, :updated_at, :created_at
|
||||
|
||||
scope :active, -> { where.not(status: STATUS_CLOSED) }
|
||||
scope :inactive, -> { where(status: STATUS_CLOSED) }
|
||||
scope :joinable, -> { where(status: STATUS_OPEN) }
|
||||
|
@ -57,7 +55,7 @@ class Contest < ActiveRecord::Base
|
|||
has_many :predictions, :through => :matches
|
||||
has_many :brackets
|
||||
has_many :preds_with_score, -> {
|
||||
select("predictions.id, predictions.user_id
|
||||
select("predictions.id, predictions.user_id,
|
||||
SUM(result) AS correct,
|
||||
SUM(result)/COUNT(*)*100 AS score,
|
||||
COUNT(*) AS total")
|
||||
|
|
|
@ -88,9 +88,9 @@ class Match < ActiveRecord::Base
|
|||
scope :on_day, -> (day) { where("match_time > ? and match_time < ?", day.beginning_of_day, day.end_of_day) }
|
||||
scope :on_week, -> (time) { where("match_time > ? and match_time < ?", time.beginning_of_week, time.end_of_week) }
|
||||
scope :of_contester, -> (contester) { where("contester1_id = ? OR contester2_id = ?", contester.id, contester.id) }
|
||||
scope :of_user, -> (user) { includes(:matchers).where("matchers.user_id = ?", user.id) }
|
||||
scope :of_user, -> (user) { includes(:matchers).where(matchers: {user_id: user.id}) }
|
||||
scope :of_team, -> (team) { includes({:contester1 => :team, :contester2 => :team}).where("teams.id = ? OR teams_contesters.id = ?", team.id, team.id) }
|
||||
scope :of_userteam, -> (user, team) { eager_load({:matchers => {:contester => :team}}).where("teams.id = ? AND matchers.user_id = ?", team.id, user.id) }
|
||||
scope :of_userteam, -> (user, team) { includes({:matchers => {:contester => :team}}).where(teams: {id: team.id}, matchers: {user_id: user.id}) }
|
||||
scope :within_time, -> (from, to) { where("match_time > ? AND match_time < ?", from.utc, to.utc) }
|
||||
scope :around, -> (time) { where("match_time > ? AND match_time < ?", time.ago(MATCH_LENGTH).utc, time.ago(-MATCH_LENGTH).utc) }
|
||||
scope :after, -> (time) { where("match_time > ? AND match_time < ?", time.utc, time.ago(-MATCH_LENGTH).utc) }
|
||||
|
|
|
@ -27,7 +27,7 @@ class Prediction < ActiveRecord::Base
|
|||
validates_inclusion_of :score2, :in => 0..99, :message => "Invalid score"
|
||||
validates_uniqueness_of :match_id, :scope => :user_id
|
||||
|
||||
scope :with_contest, -> { include({:match => :contest}) }
|
||||
scope :with_contest, -> { includes({:match => :contest}) }
|
||||
|
||||
belongs_to :match
|
||||
belongs_to :user
|
||||
|
|
|
@ -41,7 +41,7 @@ class Teamer < ActiveRecord::Base
|
|||
scope :active, -> { where("teamers.rank >= ?", RANK_MEMBER) }
|
||||
scope :leaders, -> { where("teamers.rank >= ?", RANK_DEPUTEE) }
|
||||
scope :of_team, -> (team) { where("teamers.team_id" => team.id) }
|
||||
scope :active_teams, -> { includes(:team).where("teams.active = ?", true) }
|
||||
scope :active_teams, -> { includes(:team).where(teams: {active: true}) }
|
||||
scope :unique_by_team, -> { group("user_id, team_id") }
|
||||
scope :ordered, -> { order("rank DESC, created_at ASC") }
|
||||
scope :historic, -> (user, time) {
|
||||
|
|
|
@ -109,7 +109,7 @@ class Topic < ActiveRecord::Base
|
|||
return false unless cuser
|
||||
errors.add :bans, I18n.t(:bans_mute) if cuser.banned?(Ban::TYPE_MUTE) and forum != Forum::BANS
|
||||
errors.add :bans, I18n.t(:registered_for_week) unless cuser.verified?
|
||||
(Forum.available_to(cuser, Forumer::ACCESS_TOPIC).of_forum(forum).first and errors.size == 0)
|
||||
Forum.available_to(cuser, Forumer::ACCESS_TOPIC).where(id: forum_id) and errors.size == 0
|
||||
end
|
||||
|
||||
def can_update? cuser
|
||||
|
@ -129,6 +129,6 @@ class Topic < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.params(params, cuser)
|
||||
params.permit(:state, :title, :forum_id, :user_id)
|
||||
params.require(:topic).permit(:state, :title, :forum_id, :user_id, :first_post)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue