Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #18 from kbrock/next_batch

support int arrays
  • Loading branch information...
commit dad72e152ef22b0d4c19e57b595ff34da5797621 2 parents 2a8908f + dfb9e54
Dan McClain authored October 05, 2012
10  lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb
@@ -62,15 +62,9 @@ def string_to_array(value)
62 62
       end
63 63
 
64 64
       def type_cast_array(array)
65  
-        casted_array = []
66  
-        array.each do |value|
67  
-          if Array === value
68  
-            casted_array.push type_cast_array(value)
69  
-          else
70  
-            casted_array.push type_cast value
71  
-          end
  65
+        array.map do |value|
  66
+          Array === value ? type_cast_array(value) : type_cast(value)
72 67
         end
73  
-        casted_array
74 68
       end
75 69
 
76 70
       def type_cast_code_with_extended_types(var_name)
1  lib/postgres_ext/arel/visitors/to_sql.rb
@@ -21,6 +21,7 @@ def visit_IPAddr value
21 21
       end
22 22
 
23 23
       def change_string value
  24
+        return value unless value.is_a?(String)
24 25
         if value.match /"|,|\{/
25 26
           value.gsub(/"/, "\"").gsub(/'/,'"')
26 27
         else
7  spec/arel/array_spec.rb
@@ -6,6 +6,7 @@
6 6
   before do
7 7
     adapter.create_table :arel_arrays, :force => true do |t|
8 8
       t.string :tags, :array => true
  9
+      t.integer :tag_ids, :array => true
9 10
     end
10 11
 
11 12
     class ArelArray < ActiveRecord::Base
@@ -25,6 +26,12 @@ class ArelArray < ActiveRecord::Base
25 26
       arel_table.where(arel_table[:tags].array_overlap(['tag','tag 2'])).to_sql.should match /&& '\{tag,tag 2\}'/
26 27
     end
27 28
 
  29
+    it 'converts Arel array_overlap statment' do
  30
+      arel_table = ArelArray.arel_table
  31
+
  32
+      arel_table.where(arel_table[:tag_ids].array_overlap([1,2])).to_sql.should match /&& '\{1,2\}'/
  33
+    end
  34
+
28 35
     it 'returns matched records' do
29 36
       one = ArelArray.create!(:tags => ['one'])
30 37
       two = ArelArray.create!(:tags => ['two'])

0 notes on commit dad72e1

Please sign in to comment.
Something went wrong with that request. Please try again.