好的,这是我的错误
Mysql2::Error: Unknown column 'events.user_id' in 'where clause': SELECT `users`.*
FROM `users` INNER JOIN `events` ON `users`.`id` = `events`.`author_id`
WHERE `events`.`user_id` = 1
产生此冲突的行位于user
模型
has_many :events_created, :through => :events, :source => :author
总而言之,我知道发生了上述错误,因为在event
模型中有以下行(在我的数据库中搜索events.user_id
而不是events.author_id
belongs_to :author, :class_name => "User"
有没有办法让它搜索此集合中的events.author_id
?
答案 0 :(得分:1)
belongs_to :author, :class_name => "User", :foreign_key => "author_id"