Class: Cash::Query::PrimaryKey

Inherits:
Abstract
  • Object
show all
Defined in:
lib/cash/query/primary_key.rb

Constant Summary

Constants inherited from Abstract

Abstract::DESC

Instance Method Summary collapse

Methods inherited from Abstract

#calculation?, #limit, #offset, #order, perform

Constructor Details

#initialize(active_record, ids, options1, options2) ⇒ PrimaryKey

Returns a new instance of PrimaryKey.



4
5
6
7
8
9
10
11
# File 'lib/cash/query/primary_key.rb', line 4

def initialize(active_record, ids, options1, options2)
  super(active_record, options1, options2)
  @expects_array = ids.first.kind_of?(Array)
  @original_ids = ids
  @ids = ids.flatten.compact.uniq.collect do |object|
    object.respond_to?(:quoted_id) ? object.quoted_id : object.to_i
  end
end

Instance Method Details

#performObject

Raises:

  • (ActiveRecord::RecordNotFound)


13
14
15
16
17
18
# File 'lib/cash/query/primary_key.rb', line 13

def perform
  return [] if @expects_array && @ids.empty?
  raise ActiveRecord::RecordNotFound if @ids.empty?

  super(:conditions => { :id => @ids.first })
end