aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-16 14:43:27 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-16 14:43:27 -0700
commit6064001d642fdbd18cdfe2aafc1f17e8fb248bd1 (patch)
tree9a38ec9525a9f81eb09d873adcc87b0e1fcc2f96 /lib/arel
parent6c173acf0a2ccc4907cf55709def5752f59d0167 (diff)
downloadrails-6064001d642fdbd18cdfe2aafc1f17e8fb248bd1.tar.gz
rails-6064001d642fdbd18cdfe2aafc1f17e8fb248bd1.tar.bz2
rails-6064001d642fdbd18cdfe2aafc1f17e8fb248bd1.zip
additional test coverage for some random complex case
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/primitives/attribute.rb23
-rw-r--r--lib/arel/relations/compound.rb4
-rw-r--r--lib/arel/relations/recursion.rb10
-rw-r--r--lib/arel/relations/relation.rb2
4 files changed, 29 insertions, 10 deletions
diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb
index 9d5b98474f..9fb47d56cf 100644
--- a/lib/arel/primitives/attribute.rb
+++ b/lib/arel/primitives/attribute.rb
@@ -37,16 +37,9 @@ module Arel
ancestor == other.ancestor
end
- module Origin
- def original_relation
- relation.relation_for(self)
- end
-
- def original_attribute
- original_relation[self]
- end
+ def original_relation
+ relation.relation_for(self)
end
- include Origin
module Transformations
def self.included(klass)
@@ -76,6 +69,18 @@ module Arel
!(history & other.history).empty?
end
+ def descends_from?(other)
+ history.include?(other)
+ end
+
+ def root?
+ relation.root?
+ end
+
+ def root
+ @root ||= history.detect(&:root?)
+ end
+
def /(other)
if other then (history & other.history).size.to_f / Set.new(history + other.history).size
else 0
diff --git a/lib/arel/relations/compound.rb b/lib/arel/relations/compound.rb
index 1459c163cf..6f230c3f57 100644
--- a/lib/arel/relations/compound.rb
+++ b/lib/arel/relations/compound.rb
@@ -11,6 +11,10 @@ module Arel
@attributes ||= relation.attributes.collect { |a| a.bind(self) }
end
+ def selects
+ @selects ||= relation.selects.collect { |s| s.bind(self) }
+ end
+
# XXX
def relation_for(attribute)
join? && relation.relation_for(attribute) || self[attribute] && self
diff --git a/lib/arel/relations/recursion.rb b/lib/arel/relations/recursion.rb
index fa4d9969c9..ea8109d87d 100644
--- a/lib/arel/relations/recursion.rb
+++ b/lib/arel/relations/recursion.rb
@@ -9,9 +9,19 @@ module Arel
formatter.table self
end
+ def root?
+ true
+ end
+
def relation_for(attribute)
self[attribute] && self
end
end
end
+
+ class Relation
+ def root?
+ false
+ end
+ end
end \ No newline at end of file
diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb
index 884b743f20..25dc75e8ea 100644
--- a/lib/arel/relations/relation.rb
+++ b/lib/arel/relations/relation.rb
@@ -138,7 +138,7 @@ module Arel
# TESTME - added original_attribute because of AR
def find_attribute_matching_attribute(attribute)
attributes.select { |a| a.match?(attribute) }.max do |a1, a2|
- (attribute / a1.original_attribute) <=> (attribute / a2.original_attribute)
+ (attribute / a1.root) <=> (attribute / a2.root)
end
end
end