Ticket #11084: add_readonly_option_to_has_many_associations.diff
| File add_readonly_option_to_has_many_associations.diff, 4.2 kB (added by miloops, 5 months ago) |
|---|
-
test/models/company.rb
old new 40 40 :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000' 41 41 has_many :clients_using_finder_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE 1=1' 42 42 has_many :plain_clients, :class_name => 'Client' 43 has_many :readonly_clients, :class_name => 'Client', :readonly => true 43 44 44 45 has_one :account, :foreign_key => "firm_id", :dependent => :destroy 45 46 end -
test/cases/reflection_test.rb
old new 159 159 end 160 160 161 161 def test_reflection_of_all_associations 162 assert_equal 1 7, Firm.reflect_on_all_associations.size163 assert_equal 1 5, Firm.reflect_on_all_associations(:has_many).size162 assert_equal 18, Firm.reflect_on_all_associations.size 163 assert_equal 16, Firm.reflect_on_all_associations(:has_many).size 164 164 assert_equal 2, Firm.reflect_on_all_associations(:has_one).size 165 165 assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size 166 166 end -
test/cases/associations_test.rb
old new 544 544 assert_equal 2, companies(:first_firm).limited_clients.find_all_by_type('Client', :limit => 9_000).length 545 545 end 546 546 547 def test_dynamic_find_all_should_respect_readonly_access 548 companies(:first_firm).readonly_clients.find(:all).each { |c| assert_raise(ActiveRecord::ReadOnlyRecord) { c.save } } 549 companies(:first_firm).readonly_clients.find(:all).each { |c| assert c.readonly? } 550 end 551 547 552 def test_triple_equality 548 553 assert !(Array === Firm.find(:first).clients) 549 554 assert Firm.find(:first).clients === Array -
lib/active_record/associations/association_proxy.rb
old new 114 114 :offset => @reflection.options[:offset], 115 115 :joins => @reflection.options[:joins], 116 116 :include => @reflection.options[:include], 117 :select => @reflection.options[:select] 117 :select => @reflection.options[:select], 118 :readonly => @reflection.options[:readonly] 118 119 ) 119 120 end 120 121 -
lib/active_record/associations.rb
old new 669 669 # * <tt>:source_type</tt>: Specifies type of the source association used by <tt>has_many :through</tt> queries where the source 670 670 # association is a polymorphic +belongs_to+. 671 671 # * <tt>:uniq</tt> - if set to +true+, duplicates will be omitted from the collection. Useful in conjunction with <tt>:through</tt>. 672 # * <tt>:readonly</tt> - if set to +true+, all the associated objects are readonly through the association. Default is +false+. 672 673 # 673 674 # Option examples: 674 675 # has_many :comments, :order => "posted_on" … … 677 678 # has_many :tracks, :order => "position", :dependent => :destroy 678 679 # has_many :comments, :dependent => :nullify 679 680 # has_many :tags, :as => :taggable 681 # has_many :reports, :readonly => true 680 682 # has_many :subscribers, :through => :subscriptions, :source => :user 681 683 # has_many :subscribers, :class_name => "Person", :finder_sql => 682 684 # 'SELECT DISTINCT people.* ' + … … 1234 1236 :uniq, 1235 1237 :finder_sql, :counter_sql, 1236 1238 :before_add, :after_add, :before_remove, :after_remove, 1237 :extend 1239 :extend, :readonly 1238 1240 ) 1239 1241 1240 1242 options[:extend] = create_extension_modules(association_id, extension, options[:extend])