自定义has_many与源的未定义方法

时间:2015-02-21 04:50:01

标签: ruby-on-rails activerecord

Run.rb:
  has_many :schedule_machines, through: :schedule_locations

Schedule.rb:
  has_many :schedule_locations, dependent: :destroy
  has_many :schedule_machines, through: :schedule_locations
  has_many :assigned_schedule_machines, through: :runs, source: :schedule_machines
  has_many :runs, dependent: :destroy

当我在控制台中查看计划时,

schedule.assigned_schedule_machines

给出了一个未定义的方法。

怎么回事?

1 个答案:

答案 0 :(得分:3)

has_many :runs, dependent: :destroy
has_many :assigned_schedule_machines, through: :runs, source: :schedule_machines

您需要订购"运行"第一。 assigned_schedule想要使用运行;但是在原始代码中,运行尚未定义。