netshade-cache-money 0.2.5.2 → 0.2.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -154,7 +154,7 @@ module Cash
154
154
  end
155
155
 
156
156
  def find_from_keys(*missing_keys)
157
- missing_ids = Array(missing_keys).flatten.collect { |key| key.split('/')[2].to_i }
157
+ missing_ids = Array(missing_keys).flatten.collect { |key| key.split('/')[2] }
158
158
  find_from_ids_without_cache(missing_ids, {})
159
159
  end
160
160
  end
@@ -3,18 +3,37 @@ module Cash
3
3
  class PrimaryKey < Abstract
4
4
  def initialize(active_record, ids, options1, options2)
5
5
  super(active_record, options1, options2)
6
- @expects_array = ids.first.kind_of?(Array)
7
6
  @original_ids = ids
7
+ @keytype = active_record.columns_hash[active_record.primary_key]
8
8
  @ids = ids.flatten.compact.uniq.collect do |object|
9
- object.respond_to?(:quoted_id) ? object.quoted_id : object.to_i
9
+ object.respond_to?(:quoted_id) ? object.quoted_id : ((@keytype == :integer) ? object.to_i : object.to_s)
10
+ end
11
+ @expects_array = @ids.size > 1 || ids.first.kind_of?(Array)
12
+
13
+ if @options1[:limit] || @options1[:offset]
14
+ max = (@options1[:limit] || @ids.size)
15
+ max -= (@options1[:offset] || 0)
16
+ @expected_size = max
17
+ else
18
+ @expected_size = @ids.size
10
19
  end
11
20
  end
12
21
 
13
22
  def perform
14
23
  return [] if @expects_array && @ids.empty?
15
24
  raise ActiveRecord::RecordNotFound if @ids.empty?
16
-
17
- super(:conditions => { :id => @ids.first })
25
+ results = super(:conditions => { :id => @ids.first })
26
+ if @expects_array
27
+ if results.size != @expected_size
28
+ raise ActiveRecord::RecordNotFound.new("Couldn't find all #{@active_record.name.pluralize} with IDs (#{@ids.join(",")}) (found #{results.size} results, but was looking for #{@expected_size})")
29
+ end
30
+ else
31
+ if results.kind_of?(Array)
32
+ Rails.logger.info("Found multiple(#{results.size}) results for primary key(#{@active_record.name}-#{@ids.join(",")}), choosing first")
33
+ results = results.first
34
+ end
35
+ end
36
+ results
18
37
  end
19
38
 
20
39
  protected
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netshade-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5.2
4
+ version: 0.2.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Kallen