我有以下 STI 模型,它们具有多态关联,其查询构造错误
class Product < ApplicationRecord
has_many :images, as: :imageable
end
class OneProduct < Product
end
class Image < ApplicationRecord
belongs_to :imageable
end
Run Code Online (Sandbox Code Playgroud)
在 Rails 控制台中,当我这样做时
> OneProduct.last.icon_images
Run Code Online (Sandbox Code Playgroud)
被触发的查询是
SELECT * FROM images WHERE imageable_id = id AND imageable_type = 'Product'
Run Code Online (Sandbox Code Playgroud)
我期待着:
SELECT * from images WHERE imageable_id = id AND imageable_type = 'OneProduct'
Run Code Online (Sandbox Code Playgroud)
我期待有什么不对吗?
侧面信息:数据库是 postgres。