1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

implementing where_sql method

This commit is contained in:
Aaron Patterson 2010-10-12 14:17:26 -07:00
parent 9742785d5c
commit aebc83102b
3 changed files with 25 additions and 0 deletions

View file

@ -122,6 +122,13 @@ module Arel
Compatibility::Wheres.new @engine, @ctx.wheres
end
def where_sql
return if @ctx.wheres.empty?
viz = Visitors::WhereSql.new @engine
Nodes::SqlLiteral.new viz.accept @ctx
end
def take limit
@head.limit = limit
self

View file

@ -3,6 +3,7 @@ require 'arel/visitors/postgresql'
require 'arel/visitors/mysql'
require 'arel/visitors/oracle'
require 'arel/visitors/join_sql'
require 'arel/visitors/where_sql'
require 'arel/visitors/order_clauses'
require 'arel/visitors/dot'

View file

@ -379,6 +379,23 @@ module Arel
end
end
describe 'where_sql' do
it 'gives me back the where sql' do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.where table[:id].eq 10
manager.where_sql.should be_like %{ WHERE "users"."id" = 10 }
end
it 'returns nil when there are no wheres' do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.where_sql.should be_nil
end
end
describe 'update' do
it 'copies limits' do
engine = EngineProxy.new Table.engine