Rails has_many:通过休息

时间:2013-01-06 16:44:09

标签: ruby-on-rails ruby-on-rails-3 model

好的,这是我的错误

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

1 个答案:

答案 0 :(得分:1)

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