Rails [已解决] 在 has_many, :through 的多对多关系中,如果获得中间表的 model 内容?

evenluo · April 05, 2016 · Last by qinfanpeng replied at April 05, 2016 · 1420 hits

比如 Doctor 表和 Patient 表,关联表是 Appointment,其中 Appointment 表中有预约的额外信息,那我如果获得 appointment 呢。doctor.appointments 是不行的

—————————————— 分割线 ————————————

是可以的。。是自己的写法有误,抱歉

doctor.appointments 应该没问题啊

应该是没问题的,报啥错?

#2 楼 @qinfanpeng #1 楼 @kikyous

报的就是 NoMethodError Exception,我也不知道是为啥,难道是我的关联写法错了?我的关联写法是按照 http://guides.ruby-china.org/association_basics.html#has_many-:through-%E5%85%B3%E8%81%94 这个来的

贴代码吧

哦,我懂了。。我忘记了写 has_many :appointments 这个真是傻透了,对不起大家,请折叠我吧。。 #2 楼 @qinfanpeng #1 楼 @kikyous

You need to Sign in before reply, if you don't have an account, please Sign up first.