Class: Card::Query::CachedCountJoin

Inherits:
Join
  • Object
show all
Defined in:
lib/card/query/cached_count_join.rb

Overview

joins card query with cached count table

Instance Method Summary collapse

Constructor Details

#initialize(cardquery, right) ⇒ CachedCountJoin

Returns a new instance of CachedCountJoin.



5
6
7
8
9
10
# File 'lib/card/query/cached_count_join.rb', line 5

def initialize cardquery, right
  validate_right right
  super(side: :left, from: cardquery, from_field: "id",
        to: %w[counts counts_table left_id])
  @conditions << "counts_table.right_id = #{@right_id}"
end

Instance Method Details

#validate_right(right) ⇒ Object

Raises:

  • (Card::Error::BadQuery)


12
13
14
15
16
17
18
# File 'lib/card/query/cached_count_join.rb', line 12

def validate_right right
  raise Card::Error::BadQuery, "sort by cached_count: no right given" unless right
  unless (@right_id = right.card_id)
    raise Card::Error::BadQuery,
          "cached count for +#{right}: #{right} does not exist"
  end
end