rails 4 has_many :through、has_one :through和Has_many :through, :source
文章目录
has_many :through
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, through: :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
end
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, through: :appointments
end
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论