diff --git a/lib/postgres_ext/arel/visitors/to_sql.rb b/lib/postgres_ext/arel/visitors/to_sql.rb index 95dcd6a..8a248ed 100644 --- a/lib/postgres_ext/arel/visitors/to_sql.rb +++ b/lib/postgres_ext/arel/visitors/to_sql.rb @@ -3,9 +3,10 @@ module Arel module Visitors class ToSql - def visit_Array o - if last_column.respond_to?(:array) && last_column.array - quoted o + def visit_Array o, a + column = a.relation.engine.columns.find { |col| col.name == a.name.to_s } if a + if column && column.respond_to?(:array) && column.array + quoted o, a else o.empty? ? 'NULL' : o.map { |x| visit x }.join(', ') end diff --git a/lib/postgres_ext/arel/visitors/visitor.rb b/lib/postgres_ext/arel/visitors/visitor.rb index 4209034..965ac28 100644 --- a/lib/postgres_ext/arel/visitors/visitor.rb +++ b/lib/postgres_ext/arel/visitors/visitor.rb @@ -4,33 +4,33 @@ module Visitors class Visitor # We are adding our visitors to the main visitor for the time being until the right spot is found to monkey patch private - def visit_Arel_Nodes_ContainedWithin o - "#{visit o.left} << #{visit o.right}" + def visit_Arel_Nodes_ContainedWithin o, a = nil + "#{visit o.left, a} << #{visit o.right, o.left}" end - def visit_Arel_Nodes_ContainedWithinEquals o - "#{visit o.left} <<= #{visit o.right}" + def visit_Arel_Nodes_ContainedWithinEquals o, a = nil + "#{visit o.left, a} <<= #{visit o.right, o.left}" end - def visit_Arel_Nodes_Contains o + def visit_Arel_Nodes_Contains o, a = nil left_column = o.left.relation.engine.columns.find { |col| col.name == o.left.name.to_s } if left_column && left_column.respond_to?(:array) && left_column.array - "#{visit o.left} @> #{visit o.right}" + "#{visit o.left, a} @> #{visit o.right, o.left}" else - "#{visit o.left} >> #{visit o.right}" + "#{visit o.left, a} >> #{visit o.right, o.left}" end end - def visit_Arel_Nodes_ContainsEquals o - "#{visit o.left} >>= #{visit o.right}" + def visit_Arel_Nodes_ContainsEquals o, a = nil + "#{visit o.left, a} >>= #{visit o.right, o.left}" end - def visit_Arel_Nodes_Overlap o - "#{visit o.left} && #{visit o.right}" + def visit_Arel_Nodes_Overlap o, a = nil + "#{visit o.left, a} && #{visit o.right, o.left}" end - def visit_IPAddr value + def visit_IPAddr value, a = nil "'#{value.to_s}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}'" end end