Hello everyone. I need some guidance! I need to cr...
# orm-help
s
Hello everyone. I need some guidance! I need to create 4 level deep nested table schema:
Company -> Service -> Specialty -> Sub-Specialty
Each table will have only unique records. I tried creating a relations table but couldn't figure it out. How can I create this structure? Here is the datamodel I have right now:
Copy code
type Company {
  id: ID! @id
  name: String! @unique
}
type Service {
  id: ID! @id
  name: String! @unique
  companies: [Company]! @relation
  specialties: [Specialty] @relation
}

type Specialty {
  id: ID! @id
  name: String! @unique
  companies: [Company]! @relation
  services: [Service] @relation
  sub_specialties: [Specialty] @relation
}
s
Company will have multiple services, Services will have multiple specialties, specialty will have self-relation multiple specialty .
Company
gotta have :
Copy code
services: [Service!] @relation
specialties: [Specialty] @relation
You can have two way relation if you want. it's upto you.
s
Thanks for the answer @Sachin Jani. I need to show Specialties under Service though. I tried earlier the way you said, but in that case, Specialties under Service duplicates under different countries.
s
What's the blocker now?
s
You add a Service to a Company1 and then Company2. All specialties for Company1 goes to Company2 too. I solved it by creating the whole tree at once with nested create methods and replace the everytime user wants to update the tree. Thanks for your help!
👍 1