Rails has_many :throught breaks



这就是我的错误

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模型中有以下行(在我的db中搜索events.user_id而不是events.author_id

)

belongs_to :author, :class_name => "User"

是否有办法使它搜索events.author_id在这个集合?

belongs_to :author, :class_name => "User", :foreign_key => "author_id"

相关内容

  • 没有找到相关文章

最新更新