aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r--lib/arel/algebra/extensions.rb1
-rw-r--r--lib/arel/algebra/extensions/symbol.rb5
-rw-r--r--lib/arel/algebra/primitives/attribute.rb4
-rw-r--r--lib/arel/algebra/primitives/expression.rb2
-rw-r--r--lib/arel/algebra/relations/relation.rb11
-rw-r--r--lib/arel/algebra/relations/utilities/externalization.rb2
6 files changed, 19 insertions, 6 deletions
diff --git a/lib/arel/algebra/extensions.rb b/lib/arel/algebra/extensions.rb
index 5338fee989..694dc60a2a 100644
--- a/lib/arel/algebra/extensions.rb
+++ b/lib/arel/algebra/extensions.rb
@@ -1,4 +1,5 @@
require 'arel/algebra/extensions/object'
require 'arel/algebra/extensions/class'
require 'arel/algebra/extensions/array'
+require 'arel/algebra/extensions/symbol'
require 'arel/algebra/extensions/hash'
diff --git a/lib/arel/algebra/extensions/symbol.rb b/lib/arel/algebra/extensions/symbol.rb
new file mode 100644
index 0000000000..787867bdc3
--- /dev/null
+++ b/lib/arel/algebra/extensions/symbol.rb
@@ -0,0 +1,5 @@
+class Symbol
+ def to_attribute(relation)
+ Arel::Attribute.new(relation, self)
+ end
+end \ No newline at end of file
diff --git a/lib/arel/algebra/primitives/attribute.rb b/lib/arel/algebra/primitives/attribute.rb
index 7a4411e248..aa1f2ae00c 100644
--- a/lib/arel/algebra/primitives/attribute.rb
+++ b/lib/arel/algebra/primitives/attribute.rb
@@ -39,8 +39,8 @@ module Arel
relation == new_relation ? self : Attribute.new(new_relation, name, :alias => @alias, :ancestor => self)
end
- def to_attribute
- self
+ def to_attribute(relation)
+ bind(relation)
end
end
include Transformations
diff --git a/lib/arel/algebra/primitives/expression.rb b/lib/arel/algebra/primitives/expression.rb
index 989397720c..5566e2d0b7 100644
--- a/lib/arel/algebra/primitives/expression.rb
+++ b/lib/arel/algebra/primitives/expression.rb
@@ -22,7 +22,7 @@ module Arel
new_relation == relation ? self : self.class.new(attribute.bind(new_relation), @alias, self)
end
- def to_attribute
+ def to_attribute(relation)
Attribute.new(relation, @alias, :ancestor => self)
end
end
diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb
index fe8cab4b02..c38ab0e9c5 100644
--- a/lib/arel/algebra/relations/relation.rb
+++ b/lib/arel/algebra/relations/relation.rb
@@ -31,7 +31,7 @@ module Arel
def join(other_relation = nil, join_class = InnerJoin)
case other_relation
when String
- StringJoin.new(other_relation, self)
+ StringJoin.new(self, other_relation)
when Relation
JoinOperation.new(join_class, self, other_relation)
else
@@ -85,7 +85,8 @@ module Arel
find_attribute_matching_name(index)
when Attribute, Expression
find_attribute_matching_attribute(index)
- when Array
+ when ::Array
+ # TESTME
index.collect { |i| self[i] }
end
end
@@ -100,6 +101,12 @@ module Arel
end
end
+ def position_of(attribute)
+ (@position_of ||= Hash.new do |h, attribute|
+ h[attribute] = attributes.index(self[attribute])
+ end)[attribute]
+ end
+
private
def matching_attributes(attribute)
(@matching_attributes ||= attributes.inject({}) do |hash, a|
diff --git a/lib/arel/algebra/relations/utilities/externalization.rb b/lib/arel/algebra/relations/utilities/externalization.rb
index bd067f2304..13758ccec9 100644
--- a/lib/arel/algebra/relations/utilities/externalization.rb
+++ b/lib/arel/algebra/relations/utilities/externalization.rb
@@ -8,7 +8,7 @@ module Arel
end
def attributes
- @attributes ||= relation.attributes.collect(&:to_attribute).collect { |a| a.bind(self) }
+ @attributes ||= relation.attributes.collect { |a| a.to_attribute(self) }
end
end