how do i add rows to the associations table in a has_many_through relation

how do i add rows to the associations table in a has_many_through relation

Following the example models from the guide https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association you would do something like:

@physician.appointments.create(patient: @patient)

I think you can actually do @physician.patients << @patient on some cases where your join model does not require anything else, but in that case it’s more common to use a has_and_belongs_to_many association instead, if you use a has_many :through you usually want more data on the join model so you need to use the code on the previous response