Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

support int arrays #18

Merged
merged 1 commit into from

2 participants

@kbrock

Hey,

Looks like an array of integers was blowing up in the array of array conversions.

This should fix it

--Keenan

@danmcclain danmcclain merged commit dad72e1 into from
@danmcclain
Owner

Thank you, sir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 5, 2012
  1. @kbrock

    support int arrays

    kbrock authored
This page is out of date. Refresh to see the latest.
View
10 lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb
@@ -62,15 +62,9 @@ def string_to_array(value)
end
def type_cast_array(array)
- casted_array = []
- array.each do |value|
- if Array === value
- casted_array.push type_cast_array(value)
- else
- casted_array.push type_cast value
- end
+ array.map do |value|
+ Array === value ? type_cast_array(value) : type_cast(value)
end
- casted_array
end
def type_cast_code_with_extended_types(var_name)
View
1  lib/postgres_ext/arel/visitors/to_sql.rb
@@ -21,6 +21,7 @@ def visit_IPAddr value
end
def change_string value
+ return value unless value.is_a?(String)
if value.match /"|,|\{/
value.gsub(/"/, "\"").gsub(/'/,'"')
else
View
7 spec/arel/array_spec.rb
@@ -6,6 +6,7 @@
before do
adapter.create_table :arel_arrays, :force => true do |t|
t.string :tags, :array => true
+ t.integer :tag_ids, :array => true
end
class ArelArray < ActiveRecord::Base
@@ -25,6 +26,12 @@ class ArelArray < ActiveRecord::Base
arel_table.where(arel_table[:tags].array_overlap(['tag','tag 2'])).to_sql.should match /&& '\{tag,tag 2\}'/
end
+ it 'converts Arel array_overlap statment' do
+ arel_table = ArelArray.arel_table
+
+ arel_table.where(arel_table[:tag_ids].array_overlap([1,2])).to_sql.should match /&& '\{1,2\}'/
+ end
+
it 'returns matched records' do
one = ArelArray.create!(:tags => ['one'])
two = ArelArray.create!(:tags => ['two'])
Something went wrong with that request. Please try again.