How to use ActiveAdmin on models using has_many through association?

前端 未结 6 1278
南笙
南笙 2020-12-12 11:28

I am using ActiveAdmin gem in my project.

I have 2 models using has_many through association. The database schema looks exactly the same as the example in RailsGuide

6条回答
  •  轮回少年
    2020-12-12 12:16

    @monfresh @tomblomfield you can do

    has_many :appointments, ->{ includes(:patients) }, :through => :patients
    

    in the physicians model

    ...or, I'm not sure if you can use it with formtastic but you could make the scope optional with something like

    has_many :appointments :through => :patients do
      def with_patients
        includes(:patients)
      end
    end
    

    and appointment.patient wont n+1 anymore

提交回复
热议问题