uses more rails-like syntax in scopes

This commit is contained in:
David Gil
2015-09-10 13:53:47 +02:00
parent 59a99ed874
commit 8ed434cc8b
4 changed files with 7 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ class Comment < ActiveRecord::Base
scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) } scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) }
scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") } scope :with_ignored_flag, -> { where(hidden_at: nil).where.not(ignored_flag_at: nil) }
scope :flagged, -> { where("flags_count > 0") } scope :flagged, -> { where("flags_count > 0") }
scope :for_render, -> { with_hidden.includes(user: :organization) } scope :for_render, -> { with_hidden.includes(user: :organization) }

View File

@@ -27,7 +27,7 @@ class Debate < ActiveRecord::Base
scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) } scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) }
scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") } scope :with_ignored_flag, -> { where.not(ignored_flag_at: nil).where(hidden_at: nil) }
scope :flagged, -> { where("flags_count > 0") } scope :flagged, -> { where("flags_count > 0") }
scope :for_render, -> { includes(:tags) } scope :for_render, -> { includes(:tags) }
scope :sort_by_hot_score , -> { order(hot_score: :desc) } scope :sort_by_hot_score , -> { order(hot_score: :desc) }

View File

@@ -7,9 +7,9 @@ class Organization < ActiveRecord::Base
delegate :email, :phone_number, to: :user delegate :email, :phone_number, to: :user
scope :pending, -> { where('organizations.verified_at is null and rejected_at is null') } scope :pending, -> { where(verified_at: nil, rejected_at: nil) }
scope :verified, -> { where("organizations.verified_at is not null and (rejected_at is null or rejected_at < organizations.verified_at)") } scope :verified, -> { where.not(verified_at: nil).where("(rejected_at IS NULL or rejected_at < organizations.verified_at)") }
scope :rejected, -> { where("rejected_at is not null and (organizations.verified_at is null or organizations.verified_at < rejected_at)") } scope :rejected, -> { where.not(rejected_at: nil).where("(organizations.verified_at IS NULL or organizations.verified_at < rejected_at)") }
def verify def verify
update(verified_at: Time.now) update(verified_at: Time.now)

View File

@@ -31,11 +31,11 @@ module ActsAsParanoidAliases
module ClassMethods module ClassMethods
def with_confirmed_hide def with_confirmed_hide
where("confirmed_hide_at IS NOT NULL") where.not(confirmed_hide_at: nil)
end end
def without_confirmed_hide def without_confirmed_hide
where("confirmed_hide_at IS NULL") where(confirmed_hide_at: nil)
end end
def with_hidden def with_hidden
@@ -57,4 +57,3 @@ module ActsAsParanoidAliases
end end
end end
end end