Prisma category self-relation hierarchy doesn't set child categories ever and takes parent only for one category

prisma

#1

I am struggling with correctly setting up a parent-children relation for a category hierarchy. I have followed other posts on the similar lines, and had earlier asked something similar where @pantharshit00 had suggested the upsert methods I am using. But in debugging, I have come to believe that I have fundamentally misconfigured my datamodel.

type Category {
  parentCategory: Category
    @relation(name: "CategoryTreeRelation", onDelete: SET_NULL)
  subCategories: [Category!]!
    @relation(name: "CategoryTreeRelation", onDelete: SET_NULL)
}

Highlighted spaces should not be empty (i.e. null) in this attached image:

That is, Expecting results similar to answer on a SO question. Except that my self-relation is one-to-many!

I am here providing a minimal and working reproduction of the issue at: https://github.com/devautor/prisma-self-relation-bug-repro

This is worthy of someone’s 5 mins at max, be that someone :slight_smile:
Thanks!


#2

@kumargaurav.jha2895

Name you relation different otherwise they will cause a conflict:

type Category {
  parentCategory: Category
    @relation(name: "CategoryTreeRelationParent", onDelete: SET_NULL)
  subCategories: [Category!]!
    @relation(name: "CategoryTreeRelationChild", onDelete: SET_NULL)
}