Permalink
Browse files

Fixes #24 - Visitor inclusion fixed by monkeypatching Arel::Visitors:…

…:Visitor

Plan to look into monkeypatching the individual visitors
  • Loading branch information...
1 parent c6ebaeb commit 2ee134cb05d50bc053aaea18ae2bbbd84e658248 @danmcclain danmcclain committed Dec 14, 2012
@@ -1,11 +1,13 @@
require 'arel/nodes/binary'
+require 'debugger'
module Arel
module Nodes
class ContainedWithin < Arel::Nodes::Binary
def operator; :<< end
end
class ArrayOverlap < Arel::Nodes::Binary
+ def operator; '&&' end
end
end
end
@@ -1,7 +1,8 @@
-require 'arel/visitors/to_sql'
+require 'arel/visitors/visitor'
module Arel
module Visitors
- class ToSql
+ 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}"
View
@@ -32,6 +32,12 @@ class ArelArray < ActiveRecord::Base
arel_table.where(arel_table[:tag_ids].array_overlap([1,2])).to_sql.should match /&& '\{1,2\}'/
end
+ it 'works with count (and other predicates)' do
+ arel_table = ArelArray.arel_table
+
+ ArelArray.where(arel_table[:tag_ids].array_overlap([1,2])).count.should eq 0
+ end
+
it 'returns matched records' do
one = ArelArray.create!(:tags => ['one'])
two = ArelArray.create!(:tags => ['two'])

0 comments on commit 2ee134c

Please sign in to comment.