我有一个STI子类,SoftCredits :: EventBrite< SoftCredit,具有创建SoftCredit
的函数def create_activity
options = {
owner: person,
created_at: additional_data['created_at'],
updated_at: additional_data['updated_at'],
trail_item_type: "Activities::EventBriteRegistration",
trail_item_id: self.id
}
Activity.create(options)
end
活动模型是多态的
belongs_to :trail_item, :polymorphic => true
Activities :: EventBriteRegistration模型声明如下所示:
class Activities::EventBriteRegistration < SoftCredit
def self.default_scope
unscoped
end
end
我的问题是当我有一个Activity类型的Activities :: EventBriteRegistration并且我在其上查询event_brite_registration_activity.trail_item时,查询构造如下:
SELECT "soft_credits".* FROM "soft_credits" WHERE "soft_credits"."type" IN ('Activities::EventBriteRegistration') AND "soft_credits"."id" =[id] LIMIT 1.
当然,SoftCredits没有类型的活动:: EventBriteRegistration,我很困惑如何构建它,所以当我执行event_brite_registration_activity.trail_item时,它会在SoftCredit上查询以找到正确的软信用。