aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/primitives/attribute.rb18
-rw-r--r--lib/arel/relations/join.rb1
-rw-r--r--lib/arel/relations/recursion.rb10
-rw-r--r--spec/arel/integration/joins/with_aggregations_spec.rb4
-rw-r--r--spec/arel/unit/primitives/attribute_spec.rb9
5 files changed, 8 insertions, 34 deletions
diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb
index 1de2bf7cb0..bb951638e4 100644
--- a/lib/arel/primitives/attribute.rb
+++ b/lib/arel/primitives/attribute.rb
@@ -38,12 +38,11 @@ module Arel
end
def original_relation
- relation.relation_for(self)
- # root.relation
+ @original_relation ||= relation.relation_for(self)
end
def original_attribute
- original_relation[self]
+ @original_attribute ||= original_relation[self]
end
module Transformations
@@ -78,19 +77,8 @@ module Arel
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
- end
- # 1 / (history.index(other) || -1)
+ other ? (history & other.history).size : 0
end
end
include Congruence
diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb
index 8e29f0492b..88d5f45b67 100644
--- a/lib/arel/relations/join.rb
+++ b/lib/arel/relations/join.rb
@@ -39,7 +39,6 @@ module Arel
relation1.externalize.selects
end
- # XXX
def relation_for(attribute)
[
relation1.externalize.relation_for(attribute),
diff --git a/lib/arel/relations/recursion.rb b/lib/arel/relations/recursion.rb
index ea8109d87d..fa4d9969c9 100644
--- a/lib/arel/relations/recursion.rb
+++ b/lib/arel/relations/recursion.rb
@@ -9,19 +9,9 @@ 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/spec/arel/integration/joins/with_aggregations_spec.rb b/spec/arel/integration/joins/with_aggregations_spec.rb
index e6af920d32..b9cb4acc31 100644
--- a/spec/arel/integration/joins/with_aggregations_spec.rb
+++ b/spec/arel/integration/joins/with_aggregations_spec.rb
@@ -16,6 +16,10 @@ module Arel
end
describe '#attributes' do
+ it '' do
+ @relation1.join(@aggregation).on(@predicate)[@relation2[:user_id]].should_not be_nil
+ end
+
it 'it transforms aggregate expressions into attributes' do
join_with_aggregation = Join.new("INNER JOIN", @relation1, @aggregation, @predicate)
join_with_aggregation.attributes.should ==
diff --git a/spec/arel/unit/primitives/attribute_spec.rb b/spec/arel/unit/primitives/attribute_spec.rb
index 7e0155f84d..34665b5adf 100644
--- a/spec/arel/unit/primitives/attribute_spec.rb
+++ b/spec/arel/unit/primitives/attribute_spec.rb
@@ -62,20 +62,13 @@ module Arel
@doubly_aliased_relation = @aliased_relation.alias
end
- describe 'when dividing two identical attributes' do
- it "returns 1.0" do
- (@relation[:id] / @relation[:id]).should == 1.0
- (@aliased_relation[:id] / @aliased_relation[:id]).should == 1.0
- end
- end
-
describe 'when dividing two unrelated attributes' do
it "returns 0.0" do
(@relation[:id] / @relation[:name]).should == 0.0
end
end
- describe 'when dividing two similar attributes' do
+ describe 'when dividing two matching attributes' do
it 'returns a the highest score for the most similar attributes' do
(@aliased_relation[:id] / @relation[:id]) \
.should == (@aliased_relation[:id] / @relation[:id])