rails has_and_belongs_to_many dependent code example
Example 1: activerecord through
class Doctor < ApplicationRecord
has_many :patients, through: :consultation
end
Example 2: rails join table macro
create_join_table :posts, :tags
class Doctor < ApplicationRecord
has_many :patients, through: :consultation
end
create_join_table :posts, :tags