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
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
andModel1
, having objectsuser
andm1
.Now i need all messages for object
m1
usingm1.messages
, but those entries should also be havinguser_id
, so that i can also fetchuser.messages
. Tracking user is a fundamental requirement, how should we classify mails based on other models, while keeping reference touser_id
anduser_type
?Thought : How about one more polymorphic association -
context
.track context: m1
will savecontext_id
asm1.id
andcontext_type
asModel1
.Currently added polymorphic reference using migration, and added
has_many
reference to myModel1
file,still i need to use
track extra:
which required savingcontext_id
andcontext_type
individually, andmail_object.context
does not completes the association.Hope this makes some sense, would be glad to get more insights on this