mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
Make sure with_scope takes both :select and :joins into account when setting :readonly. Allows you to save records you retrieve using finders on a has_many :through associations. [Koz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6413 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Make sure with_scope takes both :select and :joins into account when setting :readonly. Allows you to save records you retrieve using method_missing on a has_many :through associations. [Koz]
|
||||
|
||||
* Allow a polymorphic :source for has_many :through associations. Closes #7143 [protocool]
|
||||
|
||||
* Consistent public/protected/private visibility for chained methods. #7813 [Dan Manges]
|
||||
|
||||
@@ -938,7 +938,7 @@ module ActiveRecord #:nodoc:
|
||||
|
||||
if f = method_scoping[:find]
|
||||
f.assert_valid_keys([ :conditions, :joins, :select, :include, :from, :offset, :limit, :order, :readonly, :lock ])
|
||||
f[:readonly] = true if !f[:joins].blank? && !f.has_key?(:readonly)
|
||||
set_readonly_option! f
|
||||
end
|
||||
|
||||
# Merge scopings
|
||||
|
||||
@@ -10,6 +10,8 @@ require 'fixtures/order'
|
||||
require 'fixtures/category'
|
||||
require 'fixtures/post'
|
||||
require 'fixtures/author'
|
||||
require 'fixtures/tag'
|
||||
require 'fixtures/tagging'
|
||||
|
||||
|
||||
class AssociationsTest < Test::Unit::TestCase
|
||||
@@ -1855,4 +1857,12 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
|
||||
projects = Project.send(:select_limited_ids_list, {:order => 'developers.created_at'}, join_dep)
|
||||
assert_equal %w(1 2), projects.scan(/\d/).sort
|
||||
end
|
||||
|
||||
def test_scoped_find_on_through_association_doesnt_return_read_only_records
|
||||
tag = Post.find(1).tags.find_by_name("General")
|
||||
|
||||
assert_nothing_raised do
|
||||
tag.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user