【发布时间】:2019-07-01 12:03:57
【问题描述】:
我有以下 STI 模型,它们具有多态关联,其查询构造错误
class Product < ApplicationRecord
has_many :images, as: :imageable
end
class OneProduct < Product
end
class Image < ApplicationRecord
belongs_to :imageable
end
在 Rails 控制台中,当我这样做时
> OneProduct.last.icon_images
被触发的查询是
SELECT * FROM images WHERE imageable_id = id AND imageable_type = 'Product'
我期待:
SELECT * from images WHERE imageable_id = id AND imageable_type = 'OneProduct'
我期待有什么不对吗?
侧面信息:数据库是 postgres。
【问题讨论】:
标签: ruby-on-rails polymorphic-associations