being able to return the id of the user with the e...
# orm-help
k
being able to return the id of the user with the email
Specifically I am trying to seed tables with m-n relationships. The docs aren't too clear on how to do this
m
What I do, I have seeding script for each model based on dependencies.
seed-user.js
,
seed-post.js
seeds user and post. I run seed-user.js before post...I have over 300 models currently.
👀 1
👍 1
r
@Kenneth Faria 👋 Could you elaborate a bit on this? There’s an article about working with M-N relations if that helps 🙂
k
Thanks @Martïn. @Ryan Thanks for getting back to me! My question was more about creating large seeding scripts specifically m-n. Following along the implicit example in the link above:
Copy code
await prisma.post.create({
  data: {
    title: 'Types of relations',
    tags: { create: [{ name: 'dev' }, { name: 'prisma' }] },
  },
})
I found it a little cumbersome to nest 2-3 levels of create (and I think also ran into problems), and currently am ingesting related data in bulk using id's. Here's an example:
Copy code
expor const container = {
    pipelineId: 1,
    dataElementMatchList: [
      {
        dataElementId: 1,
        matches: 'match pattern',
      },
    ]
}
Where there is a pipeline table, and a dataElement table and a 1-1 relationship between container and pipeline and an m-n relationship between dataElements and containers. Is there anyway when seeding to seed this data and their relationships without specifying IDs? I am doing what @Martïn suggests, but want to move away from specifying IDs so scalability and maintainability. I am also realizing that I could probably just ingest the parent seed data and run a query right? Just wanted to see what everyone does on a larger scale to seed their DBs!
r
@Kenneth Faria What issues did you face with nested writes? Was it just cumbersome to write or was there an error when performing those?
k
There was an error, but I didn't keep track of it unfortunately. But it was definitely cumbersome to write, I think I was 3 or 4 levels nested.