1

我有一个 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

我的问题是当我有一个活动类型的活动::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 没有Activities::EventBriteRegistration 类型,我很困惑应该如何构造它,所以当我执行event_brite_registration_activity.trail_item 时,它会查询SoftCredit 以找到正确的软信用。

4

0 回答 0