aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-04-12 17:23:10 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-04-12 17:23:10 -0700
commit0f3657fb70bc14720e32e5f78e521764d7a9bc06 (patch)
treed1c6e6fe6b63b834f71fcf1b30ec3da7f9bf8ac2
parentf2bc41e6f2f6b22e7a9378a43f804cd4f7a8c1da (diff)
downloadrails-0f3657fb70bc14720e32e5f78e521764d7a9bc06.tar.gz
rails-0f3657fb70bc14720e32e5f78e521764d7a9bc06.tar.bz2
rails-0f3657fb70bc14720e32e5f78e521764d7a9bc06.zip
added pending test for (difficult) problem of aliasing tables for adjacency lists
-rw-r--r--lib/active_relation/relations/alias.rb4
-rw-r--r--spec/active_relation/unit/relations/join_spec.rb13
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/active_relation/relations/alias.rb b/lib/active_relation/relations/alias.rb
index cf410c6462..4cb4913da5 100644
--- a/lib/active_relation/relations/alias.rb
+++ b/lib/active_relation/relations/alias.rb
@@ -1,7 +1,7 @@
module ActiveRelation
class Alias < Compound
attr_reader :alias
-
+
def initialize(relation, aliaz)
@relation, @alias = relation, aliaz
end
@@ -9,7 +9,7 @@ module ActiveRelation
def alias?
true
end
-
+
def ==(other)
self.class == other.class and
relation == other.relation and
diff --git a/spec/active_relation/unit/relations/join_spec.rb b/spec/active_relation/unit/relations/join_spec.rb
index c25629536d..5d554cd9ab 100644
--- a/spec/active_relation/unit/relations/join_spec.rb
+++ b/spec/active_relation/unit/relations/join_spec.rb
@@ -144,6 +144,19 @@ module ActiveRelation
end
end
+ describe 'when joining aliased relations' do
+ it 'aliases the table and attributes properly' do
+ pending
+ aliased_relation = @relation1.as(:alias)
+ @relation1.join(aliased_relation).on(@relation1[:id].eq(aliased_relation[:id])).to_sql.should be_like("
+ SELECT `users`.`id`, `users`.`name`, `alias`.`id`, `alias`.`name`
+ FROM `users`
+ INNER JOIN `alias`
+ ON `users`.`id` = `alias`.`id`
+ ")
+ end
+ end
+
describe 'when joining with a string' do
it "passes the string through to the where clause" do
Join.new("INNER JOIN asdf ON fdsa", @relation1).to_sql.should be_like("