aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-13 16:53:36 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-13 16:53:36 -0700
commit16730fdbd0ab630320aba225314aa6a1a3b450fe (patch)
treea92ac069bb47e68b3061113c6557ffb72b21071c /lib/arel
parent562a0bf634bd61f61ebb0145d7626fb484e13c53 (diff)
downloadrails-16730fdbd0ab630320aba225314aa6a1a3b450fe.tar.gz
rails-16730fdbd0ab630320aba225314aa6a1a3b450fe.tar.bz2
rails-16730fdbd0ab630320aba225314aa6a1a3b450fe.zip
fixed defect in alias
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/primitives/attribute.rb8
-rw-r--r--lib/arel/relations/aggregation.rb2
-rw-r--r--lib/arel/relations/alias.rb5
-rw-r--r--lib/arel/relations/compound.rb2
-rw-r--r--lib/arel/relations/join.rb8
-rw-r--r--lib/arel/relations/projection.rb2
-rw-r--r--lib/arel/relations/recursion.rb2
-rw-r--r--lib/arel/relations/relation.rb10
-rw-r--r--lib/arel/sessions/session.rb8
-rw-r--r--lib/arel/sql/christener.rb6
10 files changed, 22 insertions, 31 deletions
diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb
index 39de11be26..5f8618ddfc 100644
--- a/lib/arel/primitives/attribute.rb
+++ b/lib/arel/primitives/attribute.rb
@@ -46,6 +46,14 @@ module Arel
end
module Transformations
+ def self.included(klass)
+ alias_method :eql?, :==
+ end
+
+ def hash
+ name.hash + history.size.hash
+ end
+
def as(aliaz = nil)
Attribute.new(relation, name, :alias => aliaz, :ancestor => self)
end
diff --git a/lib/arel/relations/aggregation.rb b/lib/arel/relations/aggregation.rb
index 7a56834125..955a71c0b0 100644
--- a/lib/arel/relations/aggregation.rb
+++ b/lib/arel/relations/aggregation.rb
@@ -16,6 +16,6 @@ Aggregation = Struct.new(:relation) do
end
def attributes
- relation.attributes.collect(&:to_attribute)
+ @attributes ||= relation.attributes.collect(&:to_attribute)
end
end \ No newline at end of file
diff --git a/lib/arel/relations/alias.rb b/lib/arel/relations/alias.rb
index 08be02e862..d14a51f67a 100644
--- a/lib/arel/relations/alias.rb
+++ b/lib/arel/relations/alias.rb
@@ -1,13 +1,10 @@
module Arel
class Alias < Compound
include Recursion::BaseCase
+ alias_method :==, :equal?
def initialize(relation)
@relation = relation
end
-
- def ==(other)
- equal? other
- end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/compound.rb b/lib/arel/relations/compound.rb
index 663711760c..649d11e8b1 100644
--- a/lib/arel/relations/compound.rb
+++ b/lib/arel/relations/compound.rb
@@ -3,7 +3,7 @@ module Arel
attr_reader :relation
hash_on :relation
delegate :joins, :selects, :orders, :groupings, :inserts, :taken,
- :skipped, :name, :alias, :aggregation?, :column_for,
+ :skipped, :name, :aggregation?, :column_for,
:engine, :table, :relation_for, :table_sql,
:to => :relation
diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb
index b3452968e4..b7c5c3f39b 100644
--- a/lib/arel/relations/join.rb
+++ b/lib/arel/relations/join.rb
@@ -27,7 +27,7 @@ module Arel
end
def attributes
- (externalize(relation1).attributes +
+ @attributes ||= (externalize(relation1).attributes +
externalize(relation2).attributes).collect { |a| a.bind(self) }
end
@@ -44,9 +44,11 @@ module Arel
end
def relation_for(attribute)
- [externalize(relation1).relation_for(attribute), externalize(relation2).relation_for(attribute)].max do |r1, r2|
+ [
+ externalize(relation1).relation_for(attribute),
+ externalize(relation2).relation_for(attribute)
+ ].max do |r1, r2|
a1, a2 = r1 && r1[attribute], r2 && r2[attribute]
-
attribute / a1 <=> attribute / a2
end
end
diff --git a/lib/arel/relations/projection.rb b/lib/arel/relations/projection.rb
index f09d4f894b..8a08cda70c 100644
--- a/lib/arel/relations/projection.rb
+++ b/lib/arel/relations/projection.rb
@@ -7,7 +7,7 @@ module Arel
end
def attributes
- projections.collect { |p| p.bind(self) }
+ @attributes ||= projections.collect { |p| p.bind(self) }
end
def ==(other)
diff --git a/lib/arel/relations/recursion.rb b/lib/arel/relations/recursion.rb
index 90976c702b..2c6024dc30 100644
--- a/lib/arel/relations/recursion.rb
+++ b/lib/arel/relations/recursion.rb
@@ -6,7 +6,7 @@ module Arel
end
def relation_for(attribute)
- self
+ self[attribute] and self
end
def table_sql(formatter = Sql::TableReference.new(self))
diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb
index db7d746c79..c576033938 100644
--- a/lib/arel/relations/relation.rb
+++ b/lib/arel/relations/relation.rb
@@ -139,20 +139,12 @@ module Arel
attributes.detect { |a| a.named?(name) }
end
- # TESTME - added relation_for(x)[x] because of AR
+ # 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)
end
end
-
- def find_attribute_matching_attribute_with_memoization(attribute)
- @attribute_for_attribute ||= Hash.new do |h, a|
- h[a] = find_attribute_matching_attribute_without_memoization(a)
- end
- @attribute_for_attribute[attribute]
- end
- alias_method_chain :find_attribute_matching_attribute, :memoization
end
include AttributeAccessable
diff --git a/lib/arel/sessions/session.rb b/lib/arel/sessions/session.rb
index becf23b8b6..9c61d0cba1 100644
--- a/lib/arel/sessions/session.rb
+++ b/lib/arel/sessions/session.rb
@@ -44,13 +44,5 @@ module Arel
end
end
include CRUD
-
- module Transactions
- end
- include Transactions
-
- module UnitOfWork
- end
- include UnitOfWork
end
end \ No newline at end of file
diff --git a/lib/arel/sql/christener.rb b/lib/arel/sql/christener.rb
index 894f030342..26e1acab58 100644
--- a/lib/arel/sql/christener.rb
+++ b/lib/arel/sql/christener.rb
@@ -3,9 +3,9 @@ module Arel
class Christener
def name_for(relation)
@used_names ||= Hash.new(0)
- @relation_names ||= Hash.new do |h, k|
- @used_names[k.name] += 1
- h[k] = k.name + (@used_names[k.name] > 1 ? "_#{@used_names[k.name]}" : '')
+ @relation_names ||= Hash.new do |hash, relation|
+ @used_names[name = relation.name] += 1
+ hash[relation] = name + (@used_names[name] > 1 ? "_#{@used_names[name]}" : '')
end
@relation_names[relation]
end