Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11156: add_readonly_option_to_has_many_through_associations.diff

File add_readonly_option_to_has_many_through_associations.diff, 2.5 kB (added by miloops, 8 months ago)
  • test/models/author.rb

    old new  
    2020  has_many :funky_comments, :through => :posts, :source => :comments 
    2121  has_many :ordered_uniq_comments, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id' 
    2222  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   
    2425  has_many :special_posts 
    2526  has_many :special_post_comments, :through => :special_posts, :source => :comments 
    2627 
  • test/cases/associations_test.rb

    old new  
    554554    companies(:first_firm).readonly_clients.find(:all).each { |c| assert c.readonly? } 
    555555  end 
    556556 
     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 
    557562  def test_triple_equality 
    558563    assert !(Array === Firm.find(:first).clients) 
    559564    assert Firm.find(:first).clients === Array 
  • lib/active_record/associations/has_many_through_association.rb

    old new  
    145145            :order      => @reflection.options[:order], 
    146146            :limit      => @reflection.options[:limit], 
    147147            :group      => @reflection.options[:group], 
     148            :readonly   => @reflection.options[:readonly], 
    148149            :include    => @reflection.options[:include] || @reflection.source_reflection.options[:include] 
    149150          ) 
    150151 
     
    239240                         :include     => @reflection.options[:include], 
    240241                         :select      => construct_select, 
    241242                         :order       => @reflection.options[:order], 
    242                          :limit       => @reflection.options[:limit] } } 
     243                         :limit       => @reflection.options[:limit], 
     244                         :readonly    => @reflection.options[:readonly], 
     245             } } 
    243246        end 
    244247 
    245248        def construct_sql