ActiveRecord::StatementInvalid:
Mysql::Error: Unknown column 'schedules.id' in 'on clause':
SELECT `schedules`.* FROM `schedules` INNER JOIN `shops` ON
(`schedules`.`id` = `shops`.`shop_id`) INNER JOIN `areas` ON
(`areas`.`id` = `shops`.`area_id`)
Правильный оператор sql должен включать 'schedules'. 'Shop_id' = 'shops'. 'Id' вместо 'schedules'. 'Id' = 'shops'. 'Shop_id'.Что я могу изменить в своих моделях, чтобы это произошло?
Вот модели для этих трех классов:
class Area < ActiveRecord::Base
has_many :shops
has_many :schedules, :through => :shop
end
class Schedule < ActiveRecord::Base
belongs_to :shop
has_many :areas, :through => :shop
end
class Shop < ActiveRecord::Base
belongs_to :area # foreign key - area_id
has_many :schedule
end
Команда, которая создала эту команду sql: Schedule.find: all,: joins => [: shop,: area]
В db / schema.rb у меня есть:
create_table "areas", :force => true do |t|
t.string "campus"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "shops", :force => true do |t|
t.integer "area_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "schedules", :force => true do |t|
t.integer "shop_id"
t.datetime "created_at"
t.datetime "updated_at"
end