1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/models/categorization.rb
Tristan Gamilis e0cb21f5f7 Require explicit counter_cache option for has_many
Previously has_many associations assumed a counter_cache was to be used
based on the presence of an appropriately named column. This is
inconsistent, since the inverse belongs_to association will not make
this assumption. See issues #19042 #8446.
This commit checks for the presence of the counter_cache key in the
options of either the has_many or belongs_to association as well as
ensuring that the *_count column is present.
2015-04-07 17:50:41 +10:00

19 lines
753 B
Ruby

class Categorization < ActiveRecord::Base
belongs_to :post
belongs_to :category, counter_cache: true
belongs_to :named_category, :class_name => 'Category', :foreign_key => :named_category_name, :primary_key => :name
belongs_to :author
has_many :post_taggings, :through => :author, :source => :taggings
belongs_to :author_using_custom_pk, :class_name => 'Author', :foreign_key => :author_id, :primary_key => :author_address_extra_id
has_many :authors_using_custom_pk, :class_name => 'Author', :foreign_key => :id, :primary_key => :category_id
end
class SpecialCategorization < ActiveRecord::Base
self.table_name = 'categorizations'
default_scope { where(:special => true) }
belongs_to :author
belongs_to :category
end