has_many :through with counter_cache

后端 未结 4 989
悲&欢浪女
悲&欢浪女 2020-12-06 09:40

It is my understanding that when defining a :counter_cache option it is to be specified on the model that includes the belongs_to declaration. So I am a little unsure of how

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 10:17

    I can also confirm that the method outlined by Ivica Lakatos works with Rails 6 for has_many :through relationships using a join model.

    1. add patients_count to the physicians table as an integer
    2. add a counter cache to the the join model (appointment.rb): belongs_to :physician, counter_cache: :patients_count

提交回复
热议问题