Skip to content
Browse files

Relation#readonly(false) should toggle the readonly flag

  • Loading branch information...
1 parent 9f4e983 commit 92c982d973c3e3125982309ff8bb6c22608696c5 @lifo lifo committed Dec 28, 2009
View
13 activerecord/lib/active_record/relation.rb
@@ -35,12 +35,17 @@ def eager_load(*associations)
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 @@ def joins(join, join_type = nil)
@relation.join(join, join_type)
end
- create_new_relation(join_relation)
+ create_new_relation(join_relation, true)
end
def where(*args)
View
2 activerecord/test/cases/associations/inner_join_association_test.rb
@@ -64,7 +64,7 @@ def test_find_with_implicit_inner_joins_honors_readonly_with_select
end
def test_find_with_implicit_inner_joins_honors_readonly_false
- authors = Author.find(:all, :joins => :posts, :readonly => false)
+ authors = Author.joins(:posts).readonly(false).to_a
assert !authors.empty?, "expected authors to be non-empty"
assert authors.all? {|a| !a.readonly? }, "expected no authors to be readonly"
end

0 comments on commit 92c982d

Please sign in to comment.
Something went wrong with that request. Please try again.