Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add :readonly option to HasManyThrough associations. Closes #11156 [m…
…iloops]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8989 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
lifo committed Mar 7, 2008
1 parent 8a35164 commit e117350
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Add :readonly option to HasManyThrough associations. #11156 [miloops]

* Improve performance on :include/:conditions/:limit queries by selectively joining in the pre-query. #9560 [dasil003]

* Perf fix: Avoid the use of named block arguments. Closes #11109 [adymo]
Expand Down
Expand Up @@ -159,6 +159,7 @@ def find_target
:order => @reflection.options[:order],
:limit => @reflection.options[:limit],
:group => @reflection.options[:group],
:readonly => @reflection.options[:readonly],
:include => @reflection.options[:include] || @reflection.source_reflection.options[:include]
)

Expand Down Expand Up @@ -253,7 +254,9 @@ def construct_scope
:include => @reflection.options[:include],
:select => construct_select,
:order => @reflection.options[:order],
:limit => @reflection.options[:limit] } }
:limit => @reflection.options[:limit],
:readonly => @reflection.options[:readonly],
} }
end

def construct_sql
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/associations_test.rb
Expand Up @@ -554,6 +554,11 @@ def test_dynamic_find_all_should_respect_readonly_access
companies(:first_firm).readonly_clients.find(:all).each { |c| assert c.readonly? }
end

def test_cant_save_has_many_readonly_association
authors(:david).readonly_comments.each { |c| assert_raise(ActiveRecord::ReadOnlyRecord) { c.save! } }
authors(:david).readonly_comments.each { |c| assert c.readonly? }
end

def test_triple_equality
assert !(Array === Firm.find(:first).clients)
assert Firm.find(:first).clients === Array
Expand Down
3 changes: 2 additions & 1 deletion activerecord/test/models/author.rb
Expand Up @@ -20,7 +20,8 @@ def testing_proxy_target
has_many :funky_comments, :through => :posts, :source => :comments
has_many :ordered_uniq_comments, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id'
has_many :ordered_uniq_comments_desc, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id DESC'

has_many :readonly_comments, :through => :posts, :source => :comments, :readonly => true

has_many :special_posts
has_many :special_post_comments, :through => :special_posts, :source => :comments

Expand Down

0 comments on commit e117350

Please sign in to comment.