Changeset 3756
- Timestamp:
- 03/04/06 15:11:17 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (1 diff)
- trunk/activerecord/test/associations_join_model_test.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/db_definitions/schema.rb (modified) (2 diffs)
- trunk/activerecord/test/fixtures/tagging.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r3753 r3756 1 1 *SVN* 2 3 * Make counter_cache work with polymorphic belongs_to [Jamis Buck] 2 4 3 5 * Fixed that calling HasOneProxy#build_model repeatedly would cause saving to happen #4058 [anna@wota.jp] trunk/activerecord/lib/active_record/associations.rb
r3681 r3756 507 507 end 508 508 509 if options[:counter_cache]510 module_eval(511 "after_create '#{reflection.class_name}.increment_counter(\"#{self.to_s.underscore.pluralize + "_count"}\", #{reflection.primary_key_name})" +512 " unless #{reflection.name}.nil?'"513 )514 515 module_eval(516 "before_destroy '#{reflection.class_name}.decrement_counter(\"#{self.to_s.underscore.pluralize + "_count"}\", #{reflection.primary_key_name})" +517 " unless #{reflection.name}.nil?'"518 )519 end520 521 509 # deprecated api 522 510 deprecated_has_association_method(reflection.name) 523 511 deprecated_association_comparison_method(reflection.name, reflection.class_name) 512 end 513 514 if options[:counter_cache] 515 module_eval( 516 "after_create '#{reflection.name}.class.increment_counter(\"#{self.to_s.underscore.pluralize + "_count"}\", #{reflection.primary_key_name})" + 517 " unless #{reflection.name}.nil?'" 518 ) 519 520 module_eval( 521 "before_destroy '#{reflection.name}.class.decrement_counter(\"#{self.to_s.underscore.pluralize + "_count"}\", #{reflection.primary_key_name})" + 522 " unless #{reflection.name}.nil?'" 523 ) 524 524 end 525 525 end trunk/activerecord/test/associations_join_model_test.rb
r3623 r3756 105 105 assert_equal [authors(:mary)], posts(:authorless).authors 106 106 end 107 108 def test_belongs_to_polymorphic_with_counter_cache 109 assert_equal 0, posts(:welcome)[:taggings_count] 110 tagging = posts(:welcome).taggings.create(:tag => tags(:general)) 111 assert_equal 1, posts(:welcome, :reload)[:taggings_count] 112 tagging.destroy 113 assert posts(:welcome, :reload)[:taggings_count].zero? 114 end 107 115 end trunk/activerecord/test/fixtures/db_definitions/schema.rb
r3279 r3756 9 9 create_table "tags", :force => true do |t| 10 10 t.column "name", :string 11 t.column :taggings_count, :integer, :default => 0 11 12 end 12 13 … … 17 18 end 18 19 20 add_column :posts, :taggings_count, :integer, :default => 0 21 19 22 end trunk/activerecord/test/fixtures/tagging.rb
r3209 r3756 1 1 class Tagging < ActiveRecord::Base 2 2 belongs_to :tag 3 belongs_to :taggable, :polymorphic => true 3 belongs_to :taggable, :polymorphic => true, :counter_cache => true 4 4 end