【发布时间】:2012-10-14 02:23:44
【问题描述】:
假设我有一个模型 Doctor 和一个模型 Patient。一个Patient belongs_to a Doctor。
Doctor 有一个属性 office。
如果给定Patient p,我希望能够说p.office 并访问p 的医生的office。
我总是可以写一个方法
class Patient
belongs_to :doctor
def office
self.doctor.office
end
但是有没有更自动化的方法可以将所有Doctor 的属性方法暴露给Patient?也许使用method_missing 有某种包罗万象的方法?
【问题讨论】:
标签: ruby-on-rails ruby activerecord model