Hey everyone, I currently have an implicit many-to...
# orm-help
u
Hey everyone, I currently have an implicit many-to-many relation in my database model. I want to switch to an explicit definition, and add some metadata to this relation. Is there any guide or best practices for this? It seems like a painful process to do manually.
👀 1
a
Hey Ural! If you share the relevant parts of your schema, I can try to give you some pointers 🙂.
u
Hey, sorry for the late response I didn't see your message. So I have an
Entity
table, and an
Article
table.
Copy code
model Article {
  id             Int        @id @default(autoincrement())
  mentionedEntities Entity[]
...
}

model Entity {
  id                 Int             @id @default(autoincrement())
  mentioningArticles Article[]
  ...
}
What I want is, to add some metadata to this relation, like
Copy code
ArticleToEntity {
article
articleId
entity
entityId
sentiment float <-- this is the metadata I'm talking about
}
The problem is, I already have the data in the generated
_ArticleToEntity
table, and code that is interacting with this schema. Should I take down the app, update schema, copy stuff, and restart the app after adjusting the code?
a
Take a look at this repository that demonstrates the full workflow and let me know if you have any questions. We will take also look at bringing a full guide into our documentation 🙏.
u
Oh that looks great, thanks! One question: this guide doesn't say anything about actually copying over the data. I'm guessing that's not part of the process. Does that mean I should copy over the data manually, say using SQL?
a
Yeah, I think after creating the new join table, a SQL script to migrate over the existing data is your best bet 👍.