You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey there folks! I've reached a point where I'm stuck with a problem and don't know where to go from here. I'll explain the problem with some info about the database modeling.
Hope someone has insights about this as I'm stuck on it for two days already. Appreciate it very much, thanks in advance. :)
The problem
I have a database model where both users and organizations can have multiple contact mechanisms. I've used exclusive polymorphic associations to model this (see contact_mechanisms table). The trick part is that contact mechanisms have three different subtypes (address, email and phone).
What I'm stuck at is when trying to move this modeling to Objection. For example in the OrganizationModel, I've tried to model it using the contact_mechanisms table as an association table and map the relation directly to the subtype. The problem is that when I try to create a new phone relation, the contact_mechanisms record is created after the phone one, so I don't have a contact_mechanism_id to associate with the phone record.
Not sure what I'm doing wrong here, and where to go. I didn't want to make another polymorphic association with all subtypes ids inside the contact_mechanisms table, but I'm not sure what would be the alternative.
This discussion was converted from issue #2330 on July 05, 2023 20:34.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey there folks! I've reached a point where I'm stuck with a problem and don't know where to go from here. I'll explain the problem with some info about the database modeling.
Hope someone has insights about this as I'm stuck on it for two days already. Appreciate it very much, thanks in advance. :)
The problem
I have a database model where both users and organizations can have multiple contact mechanisms. I've used exclusive polymorphic associations to model this (see
contact_mechanisms
table). The trick part is that contact mechanisms have three different subtypes (address, email and phone).What I'm stuck at is when trying to move this modeling to Objection. For example in the
OrganizationModel
, I've tried to model it using thecontact_mechanisms
table as an association table and map the relation directly to the subtype. The problem is that when I try to create a new phone relation, thecontact_mechanisms
record is created after the phone one, so I don't have acontact_mechanism_id
to associate with the phone record.Not sure what I'm doing wrong here, and where to go. I didn't want to make another polymorphic association with all subtypes ids inside the
contact_mechanisms
table, but I'm not sure what would be the alternative.The model
The database
Beta Was this translation helpful? Give feedback.
All reactions