【发布时间】:2015-04-07 03:17:30
【问题描述】:
Rails Guide for associations' has_many section中的例子如下:
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
可以通过 API 管理连接模型的集合。例如,如果您分配
physician.patients = patients
会为新关联的对象创建新的连接模型,如果其中一些已经消失,它们的行将被删除。”
我想了解:
1) physician.patients = patients 行在哪里出现?
2) 分配给physician.patients 的patients 是谁?
【问题讨论】:
标签: ruby-on-rails associations