Class: ModelSet::RawSQLQuery

Inherits:
SQLBaseQuery show all
Defined in:
lib/model_set/raw_sql_query.rb

Instance Attribute Summary

Attributes inherited from Query

#limit, #set_class, #sort_order

Instance Method Summary collapse

Methods inherited from SQLBaseQuery

#ids, #size

Methods inherited from Query

#after_query, after_query, before_query, #before_query, #clear_cache!, #clear_limited_cache!, #condition_ops, #initialize, #limit!, #limit_enabled?, #model_class, #model_name, #offset, on_exception, #on_exception, #order_by!, #page, #page!, #pages, #table_name, #transform_condition, #unlimited!, #unsorted!

Constructor Details

This class inherits a constructor from ModelSet::Query

Instance Method Details

#countObject



14
15
16
17
# File 'lib/model_set/raw_sql_query.rb', line 14

def count
  # The only way to get the count if there is a limit is to fetch all ids without the limit.
  @count ||= limit ? fetch_id_set(@sql).size : size
end

#sqlObject



10
11
12
# File 'lib/model_set/raw_sql_query.rb', line 10

def sql
  "#{@sql} #{limit_clause}"
end

#sql=(sql) ⇒ Object



3
4
5
6
7
8
# File 'lib/model_set/raw_sql_query.rb', line 3

def sql=(sql)
  @sql = sanitize_condition(sql)
  ['LIMIT', 'OFFSET'].each do |term|
    raise "#{term} not permitted in raw sql" if @sql.match(/ #{term} \d+/i)
  end
end