Skip to content

Commit

Permalink
Cache Relation#to_sql
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Jan 2, 2010
1 parent 0d1a2a3 commit e9ebf8b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions activerecord/lib/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit e9ebf8b

Please sign in to comment.