我有以下代码:
class Location < ActiveRecord::Base
has_many :geolocations, :as => :geotaggable, :dependent => :destroy
end
class Geolocation < ActiveRecord::Base
belongs_to :geotaggable, :polymorphic => true
end
当我执行:Location.first.geolocations
时,我的控制台显示以下SQL:
←[1m←[36mGeolocation Load (2.0ms)←[0m ←[1mSELECT `geolocations`.* FROM `geolo
cations` WHERE `geolocations`.`geotaggable_id` = 1←[0m
当我执行:Location.find(:first, :include => :geolocations)
时,我的控制台会显示此SQL:
←[1m←[36mGeolocation Load (1.0ms)←[0m ←[1mSELECT `geolocations`.* FROM `geolo
cations` WHERE `geolocations`.`geotaggable_type` = 'Location' AND (((`geolocatio
ns`.`geotaggable_id` = 1)))←[0m
我检查了我的项目并发现每当我有多态关联时,多态类型都不会包含在SQL查询中。
这是预期的行为还是我错过了什么?
我正在使用rails 3.2.0.rc1和Ruby 1.9.3。我相信我在rails 3.0.0中也有同样的结果。