aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel.rb1
-rw-r--r--lib/arel/compatibility/wheres.rb29
-rw-r--r--lib/arel/select_manager.rb4
-rw-r--r--spec/arel/activerecord_compat_spec.rb18
4 files changed, 52 insertions, 0 deletions
diff --git a/lib/arel.rb b/lib/arel.rb
index c4e377b5bc..acb270728f 100644
--- a/lib/arel.rb
+++ b/lib/arel.rb
@@ -3,6 +3,7 @@ require 'arel/crud'
require 'arel/version'
require 'arel/table'
require 'arel/attributes'
+require 'arel/compatibility/wheres'
#### these are deprecated
# The Arel::Relation constant is referenced in Rails
diff --git a/lib/arel/compatibility/wheres.rb b/lib/arel/compatibility/wheres.rb
new file mode 100644
index 0000000000..eeb7a2fa38
--- /dev/null
+++ b/lib/arel/compatibility/wheres.rb
@@ -0,0 +1,29 @@
+module Arel
+ module Compatibility # :nodoc:
+ class Wheres # :nodoc:
+ include Enumerable
+
+ module Value # :nodoc:
+ attr_accessor :visitor
+ def value
+ visitor.accept self
+ end
+ end
+
+ def initialize engine, collection
+ @engine = engine
+ @collection = collection
+ end
+
+ def each
+ to_sql = Visitors::ToSql.new @engine
+
+ @collection.each { |c|
+ c.extend(Value)
+ c.visitor = to_sql
+ yield c
+ }
+ end
+ end
+ end
+end
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 23d85e3386..f278465c51 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -23,6 +23,10 @@ module Arel
self
end
+ def wheres
+ Compatibility::Wheres.new @engine, @ctx.wheres
+ end
+
def take limit
@head.limit = limit
self
diff --git a/spec/arel/activerecord_compat_spec.rb b/spec/arel/activerecord_compat_spec.rb
new file mode 100644
index 0000000000..a7eeb7e5ee
--- /dev/null
+++ b/spec/arel/activerecord_compat_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+module Arel
+ describe 'activerecord compatibility' do
+ describe 'select manager' do
+ it 'provides wheres' do
+ table = Table.new :users
+ manager = Arel::SelectManager.new Table.engine
+ manager.where table[:id].eq 1
+ manager.where table[:name].eq 'Aaron'
+
+ check manager.wheres.map { |x|
+ x.value
+ }.join(', ').should == "\"users\".\"id\" = 1, \"users\".\"name\" = 'Aaron'"
+ end
+ end
+ end
+end