这是连接两个模型的方法
User.where(:id => 1).joins(:posts)
但是如何使用模块/命名空间加入两个模型
@schedules= Swimming::Classschedule.joins(:Swimming::Slot).where(:date => @date)
似乎无法正常工作(带有错误消息)
:Swimming is not a class/module
更新
我已更新为 @schedules= Swimming::Classschedule.joins(:swimming_slots).where(:date => @date)
我有这张桌子
create_table :swimming_classschedules do |t|
t.integer :slot_id
t.integer :coach_id
t.integer :level_id
t.string :note
t.timestamps
end
create_table :swimming_slots do |t|
t.string :date
t.string :start
t.string :end
t.timestamps
end
我怎么得到这个错误
Association named 'swimming_slots' was not found; perhaps you misspelled it?
更新 2
将此行添加到 Swimming::Classschedule 模块
belongs_to :swimming_slots ,:class_name=>'Swimming::Slot',:foreign_key => "slot_id"
和
将连接更改为
@schedules= Swimming::Classschedule.joins(:swimming_slots).where(:swimming_slots =>{:date => @date})
现在它可以工作了