aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r--lib/arel/algebra/relations/relation.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb
index e848c8aa1c..4cd3f8e109 100644
--- a/lib/arel/algebra/relations/relation.rb
+++ b/lib/arel/algebra/relations/relation.rb
@@ -84,7 +84,8 @@ module Arel
module AttributeAccessable
def [](index)
- case index
+ @cached_attributes ||= {}
+ @cached_attributes[index] ||= case index
when Symbol, String
find_attribute_matching_name(index)
when Attribute, Expression
@@ -96,7 +97,7 @@ module Arel
end
def find_attribute_matching_name(name)
- attributes.detect { |a| a.named?(name) }
+ attributes.detect { |a| a.named?(name) } || Attribute.new(self, name)
end
def find_attribute_matching_attribute(attribute)