diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index a7f62abe1d..ff10df96f2 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -35,12 +35,17 @@ module ActiveRecord create_new_relation(@relation, @readonly, @associations_to_preload, @eager_load_associations + Array.wrap(associations)) end - def readonly - create_new_relation(@relation, true) + def readonly(status = true) + status.nil? ? create_new_relation : create_new_relation(@relation, status) end def select(selects) - selects.present? ? create_new_relation(@relation.project(selects)) : create_new_relation + if selects.present? + frozen = @relation.joins(relation).present? ? false : @readonly + create_new_relation(@relation.project(selects), frozen) + else + create_new_relation + end end def from(from) @@ -106,7 +111,7 @@ module ActiveRecord @relation.join(join, join_type) end - create_new_relation(join_relation) + create_new_relation(join_relation, true) end def where(*args) |