Skip to content
This repository
Browse code

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...
commit e1173500379ab35734ac9101e58d6eff6552ef6e 1 parent 8a35164
Pratik authored March 07, 2008
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Add :readonly option to HasManyThrough associations. #11156 [miloops]
  4
+
3 5
 * Improve performance on :include/:conditions/:limit queries by selectively joining in the pre-query.  #9560 [dasil003]
4 6
 
5 7
 * Perf fix: Avoid the use of named block arguments.  Closes #11109 [adymo]
5  activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -159,6 +159,7 @@ def find_target
159 159
             :order      => @reflection.options[:order],
160 160
             :limit      => @reflection.options[:limit],
161 161
             :group      => @reflection.options[:group],
  162
+            :readonly   => @reflection.options[:readonly],
162 163
             :include    => @reflection.options[:include] || @reflection.source_reflection.options[:include]
163 164
           )
164 165
 
@@ -253,7 +254,9 @@ def construct_scope
253 254
                          :include     => @reflection.options[:include],
254 255
                          :select      => construct_select,
255 256
                          :order       => @reflection.options[:order],
256  
-                         :limit       => @reflection.options[:limit] } }
  257
+                         :limit       => @reflection.options[:limit],
  258
+                         :readonly    => @reflection.options[:readonly],
  259
+             } }
257 260
         end
258 261
 
259 262
         def construct_sql
5  activerecord/test/cases/associations_test.rb
@@ -554,6 +554,11 @@ def test_dynamic_find_all_should_respect_readonly_access
554 554
     companies(:first_firm).readonly_clients.find(:all).each { |c| assert c.readonly? }
555 555
   end
556 556
 
  557
+  def test_cant_save_has_many_readonly_association
  558
+    authors(:david).readonly_comments.each { |c| assert_raise(ActiveRecord::ReadOnlyRecord) { c.save! } }
  559
+    authors(:david).readonly_comments.each { |c| assert c.readonly? }
  560
+  end
  561
+
557 562
   def test_triple_equality
558 563
     assert !(Array === Firm.find(:first).clients)
559 564
     assert Firm.find(:first).clients === Array
3  activerecord/test/models/author.rb
@@ -20,7 +20,8 @@ def testing_proxy_target
20 20
   has_many :funky_comments, :through => :posts, :source => :comments
21 21
   has_many :ordered_uniq_comments, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id'
22 22
   has_many :ordered_uniq_comments_desc, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id DESC'
23  
-
  23
+  has_many :readonly_comments, :through => :posts, :source => :comments, :readonly => true
  24
+  
24 25
   has_many :special_posts
25 26
   has_many :special_post_comments, :through => :special_posts, :source => :comments
26 27
 

0 notes on commit e117350

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