diff options
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 570ba3f80d..4b53857d36 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -5,10 +5,20 @@ module ActiveRecord def initialize(klass, relation) @klass, @relation = klass, relation + @readonly = false + end + + def readonly + @readonly = true + self end def to_a - @klass.find_by_sql(@relation.to_sql) + records = @klass.find_by_sql(@relation.to_sql) + + records.each { |record| record.readonly! } if @readonly + + records end def each(&block) |