有这个:
class Event < ActiveRecord::Base
belongs_to :historizable, :polymorphic => true
end
user = User.create!
我可以:
Event.create!(:historizable => user)
但我不能:
Event.where(:historizable => user)
# Mysql2::Error: Unknown column 'events.historizable' in 'where clause'
我必须这样做:
Event.where(:historizable_id => user.id, :historizable_type => user.class.name)
更新
重现该问题的代码:https ://gist.github.com/fguillen/4732177#file-polymorphic_where_test-rb