Rails has_many :through nested form

前端 未结 3 1576
孤独总比滥情好
孤独总比滥情好 2020-12-04 15:58

I have just jumped into has_many :through association. I\'m trying to implement the ability to save data for all 3 tables (Physician, Patient

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 16:16

    "i got it working. I just changed models as follows" : quoted from Shruti in the comments above

    class Patient < ActiveRecord::Base 
      has_many :appointments, :dependent => :destroy 
      has_many :physicians, :through => :appointments
      accepts_nested_attributes_for :appointments
    end 
    
    class Appointment < ActiveRecord::Base
      belongs_to :physician 
      belongs_to :patient
      accepts_nested_attributes_for :physician
    end
    

提交回复
热议问题