Permalink
Browse files

Cache Relation#to_sql

  • Loading branch information...
1 parent 0d1a2a3 commit e9ebf8b898e0dba4ca62cca7eb26987a9117a20e @lifo lifo committed Jan 2, 2010
Showing with 5 additions and 2 deletions.
  1. +5 −2 activerecord/lib/active_record/relation.rb
@@ -2,7 +2,6 @@ module ActiveRecord
class Relation
include QueryMethods, FinderMethods, CalculationMethods
- delegate :to_sql, :to => :relation
delegate :length, :collect, :map, :each, :all?, :to => :to_a
attr_reader :relation, :klass
@@ -157,7 +156,7 @@ def reload
end
def reset
- @first = @last = @create_scope = @joined_tables = nil
+ @first = @last = @create_scope = @joined_tables = @to_sql = nil
@records = []
self
end
@@ -180,6 +179,10 @@ def primary_key
@primary_key ||= table[@klass.primary_key]
end
+ def to_sql
+ @to_sql ||= @relation.to_sql
+ end
+
protected
def method_missing(method, *args, &block)

0 comments on commit e9ebf8b

Please sign in to comment.