aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-15 09:19:54 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-26 07:24:34 -0600
commitd730e374ca99a60b08c75aab7b0ed8a846a34924 (patch)
tree179a789fd65ddc4c157f6bb088002a465755e6a8 /activerecord/test/models
parente8003c7274c4049f409740b587e4e9e1f3df37f7 (diff)
downloadrails-d730e374ca99a60b08c75aab7b0ed8a846a34924.tar.gz
rails-d730e374ca99a60b08c75aab7b0ed8a846a34924.tar.bz2
rails-d730e374ca99a60b08c75aab7b0ed8a846a34924.zip
Deprecate automatic counter caches on has_many :through
Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/post.rb2
-rw-r--r--activerecord/test/models/tagging.rb2
2 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 5f01ab0a82..a29858213b 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -88,7 +88,7 @@ class Post < ActiveRecord::Base
has_and_belongs_to_many :categories
has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
- has_many :taggings, :as => :taggable
+ has_many :taggings, :as => :taggable, :counter_cache => :tags_count
has_many :tags, :through => :taggings do
def add_joins_and_select
select('tags.*, authors.id as author_id')
diff --git a/activerecord/test/models/tagging.rb b/activerecord/test/models/tagging.rb
index f91f2ad2e9..a6c05da26a 100644
--- a/activerecord/test/models/tagging.rb
+++ b/activerecord/test/models/tagging.rb
@@ -8,6 +8,6 @@ class Tagging < ActiveRecord::Base
belongs_to :invalid_tag, :class_name => 'Tag', :foreign_key => 'tag_id'
belongs_to :blue_tag, -> { where :tags => { :name => 'Blue' } }, :class_name => 'Tag', :foreign_key => :tag_id
belongs_to :tag_with_primary_key, :class_name => 'Tag', :foreign_key => :tag_id, :primary_key => :custom_primary_key
- belongs_to :taggable, :polymorphic => true, :counter_cache => true
+ belongs_to :taggable, :polymorphic => true, :counter_cache => :tags_count
has_many :things, :through => :taggable
end