Skip to main content
deleted 4 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

scopes Scopes chaining by OR

How can iI DRY these scopes?

  scope :reputed, -> {
    joins{reputations.outer}.
    where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ?', LOWEST_VOTE, true]}
  }

  scope :reputed_or_mine, ->(user) {
    joins{reputations.outer}.
    where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ? OR purchases.user_id = ?', LOWEST_VOTE, true, user.id]}
  }

scopes chaining by OR

How can i DRY these scopes?

  scope :reputed, -> {
    joins{reputations.outer}.
    where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ?', LOWEST_VOTE, true]}
  }

  scope :reputed_or_mine, ->(user) {
    joins{reputations.outer}.
    where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ? OR purchases.user_id = ?', LOWEST_VOTE, true, user.id]}
  }

Scopes chaining by OR

How can I DRY these scopes?

  scope :reputed, -> {
    joins{reputations.outer}.
    where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ?', LOWEST_VOTE, true]}
  }

  scope :reputed_or_mine, ->(user) {
    joins{reputations.outer}.
    where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ? OR purchases.user_id = ?', LOWEST_VOTE, true, user.id]}
  }
Notice removed Draw attention by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Notice added Draw attention by ck3g
Bounty Started worth 50 reputation by ck3g
Tweeted twitter.com/#!/StackCodeReview/status/245764081905172480
Source Link
ck3g
  • 109
  • 5

scopes chaining by OR

How can i DRY these scopes?

  scope :reputed, -> {
    joins{reputations.outer}.
    where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ?', LOWEST_VOTE, true]}
  }

  scope :reputed_or_mine, ->(user) {
    joins{reputations.outer}.
    where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ? OR purchases.user_id = ?', LOWEST_VOTE, true, user.id]}
  }