ankane / ahoy_email

First-party email analytics for Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Idea] Classify mails on basis other than users

NipunBinjola opened this issue · comments

You have created a polymorphic association of user , to track email for any model . However what if i need to store context of the mail also, alongwith the user and identify what mails belong to what scenarios.

Lets say i have two different models, User and Model1 , having objects user and m1 .

Now i need all messages for object m1 using m1.messages , but those entries should also be having user_id, so that i can also fetch user.messages.
Tracking user is a fundamental requirement, how should we classify mails based on other models, while keeping reference to user_id and user_type ?

Thought : How about one more polymorphic association - context.
track context: m1 will save context_id as m1.id and context_type as Model1.

Currently added polymorphic reference using migration, and added has_many reference to my Model1 file,

class AddContextToAhoyMessages < ActiveRecord::Migration[5.0]
  def change
    add_reference :ahoy_messages, :context, polymorphic: true
  end
end

still i need to use track extra: which required saving context_id and context_type individually, and mail_object.context does not completes the association.

Hope this makes some sense, would be glad to get more insights on this