ActiveRecord, find by polymorphic attribute
问题 Having this: class Event < ActiveRecord::Base belongs_to :historizable, :polymorphic => true end user = User.create! I can: Event.create!(:historizable => user) But I can't: Event.where(:historizable => user) # Mysql2::Error: Unknown column 'events.historizable' in 'where clause' I have to do this instead: Event.where(:historizable_id => user.id, :historizable_type => user.class.name) Update Code that reproduces the issue: https://gist.github.com/fguillen/4732177#file-polymorphic_where_test