问题描述:

I have an STI subclass, SoftCredits::EventBrite < SoftCredit, that has a function called on creation of 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

Activity model is polymorphic

belongs_to :trail_item, :polymorphic => true

The Activities::EventBriteRegistration model declaration looks like so:

class Activities::EventBriteRegistration < SoftCredit

def self.default_scope

unscoped

end

end

My issue is when I have an Activity type of Activities::EventBriteRegistration and I query on it event_brite_registration_activity.trail_item, the query is construct like so:

SELECT "soft_credits".* FROM "soft_credits" WHERE "soft_credits"."type" IN ('Activities::EventBriteRegistration') AND "soft_credits"."id" =[id] LIMIT 1.

Of course, there is no type Activities::EventBriteRegistration for SoftCredits and I am confused how I should construct this so when I do event_brite_registration_activity.trail_item, it queries on SoftCredit to find the correct soft credit.

相关阅读:
Top