From d8de55cee197d887b478b134ec692776613bf998 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 20 Sep 2010 13:29:12 -0700 Subject: adding crazy code to fix the last two AR tests --- lib/arel/attributes/attribute.rb | 3 +++ lib/arel/nodes/in.rb | 4 ++++ lib/arel/select_manager.rb | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) (limited to 'lib/arel') diff --git a/lib/arel/attributes/attribute.rb b/lib/arel/attributes/attribute.rb index 28493d5cba..6bb880d211 100644 --- a/lib/arel/attributes/attribute.rb +++ b/lib/arel/attributes/attribute.rb @@ -12,6 +12,9 @@ module Arel end def in other + if Arel::SelectManager === other + other = other.to_a.map { |x| x.id } + end Nodes::In.new self, other end diff --git a/lib/arel/nodes/in.rb b/lib/arel/nodes/in.rb index 6ccf37a053..13163af11e 100644 --- a/lib/arel/nodes/in.rb +++ b/lib/arel/nodes/in.rb @@ -1,6 +1,10 @@ module Arel module Nodes class In < Equality + def initialize left, right + raise if Arel::SelectManager === right + super + end end end end diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index daef9f52ca..98d9385b0a 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -12,13 +12,17 @@ module Arel @head.limit end + def constraints + @ctx.wheres + end + def skip amount @head.offset = Nodes::Offset.new(amount) self end def where_clauses - warn "where_clauses is deprecated" if $VERBOSE + #warn "where_clauses is deprecated" if $VERBOSE to_sql = Visitors::ToSql.new @engine @ctx.wheres.map { |c| to_sql.accept c } end @@ -52,6 +56,18 @@ module Arel def from table table = Nodes::SqlLiteral.new(table) if String === table + # FIXME: this is a hack to support + # test_with_two_tables_in_from_without_getting_double_quoted + # from the AR tests. + unless @ctx.froms.empty? + source = @ctx.froms.first + + if Nodes::SqlLiteral === table && Nodes::Join === source + source.left = table + table = source + end + end + @ctx.froms = [table] self end @@ -125,8 +141,22 @@ module Arel manager.join_sql end - def to_a - raise NotImplementedError + class Row < Struct.new(:data) # :nodoc: + def id + data['id'] + end + + def method_missing(name, *args) + name = name.to_s + return data[name] if data.key?(name) + super + end + end + + def to_a # :nodoc: + warn "to_a is deprecated. Please remove it from #{caller[0]}" + # FIXME: I think `select` should be made public... + @engine.connection.send(:select, to_sql, 'AREL').map { |x| Row.new(x) } end # FIXME: this method should go away -- cgit v1.2.3