getbigger-io / prisma-fixtures

Prisma 2 Fixtures Management Tool
MIT License
25 stars 2 forks source link

Many-to-many Relationship #9

Closed renesass closed 1 year ago

renesass commented 1 year ago

Hey,

I defined a many-to-many relationship here:

model Tag {
  id       Int    @id @default(autoincrement())
  category String // user, tree, etc.
  value    String

  // All associated entities
  trees TagTree[]

  @@map("tag")
}

model Tree {
  id   Int       @id @default(autoincrement())
  name String
  tags TagTree[]

  @@map("tree")
}

model TagTree {
  tag     Tag  @relation(fields: [tagId], references: [id])
  tagId   Int
  tree    Tree @relation(fields: [treeId], references: [id])
  treeId  Int
  context Json

  @@id([treeId, tagId])
  @@map("tag_tree")
}

Now, I'm trying to seed the entities but I'm always running into Cannot read properties of undefined. I tried to use the most simple fixtures possible:

entity: tree
items:
  tree1:
    name: 'Oak'
  tree2:
    name: 'Pine'

entity: tag
items:
  tag1:
    category: 'LOCATION'
    value: 'Hamburg'
  tag2:
    category: 'LOCATION'
    value: 'Berlin'

entity: tag_tree
connectedFields: ['tag', 'tree']
items:
  tag_tree1:
    tag: '@tag1'
    tree: '@tree1'
    context: '{}'

My question is: Do you not support many-to-many relationships? Or what am I doing wrong here?

Best, René

renesass commented 1 year ago

Entity must called tagTree, then it works.