aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-20 13:29:12 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-20 13:29:12 -0700
commitd8de55cee197d887b478b134ec692776613bf998 (patch)
treed8f094320dac00f89d44a1db01aa19cc24d8138c /lib/arel
parent6f9f83e474505d7e1c253fd8f120a06e2dcd61cd (diff)
downloadrails-d8de55cee197d887b478b134ec692776613bf998.tar.gz
rails-d8de55cee197d887b478b134ec692776613bf998.tar.bz2
rails-d8de55cee197d887b478b134ec692776613bf998.zip
adding crazy code to fix the last two AR tests
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/attributes/attribute.rb3
-rw-r--r--lib/arel/nodes/in.rb4
-rw-r--r--lib/arel/select_manager.rb36
3 files changed, 40 insertions, 3 deletions
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