Relationship on a single table from multiple tables

prisma

#1

Hello,

I have the following datamodel

   type User {
  id: ID! @id
  email: String! @unique
  name: String
  password: String! 
  posts: [Post!]! @relation(name: "PostOwner", onDelete: CASCADE)// this may be a problem when i want to register a user I think
}

type Post {
  id: ID! @id
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
  published: Boolean! @default(value: false)
  title: String!
  content: String
  categories: [Category!]! @relation(name: "Category")
  tags: [Tag!]! @relation(name: "Tags")
  author: User! @relation(name: "PostOwner", onDelete: SET_NULL)

}

type Category {
  id: ID! @id
  name: [String!] @unique 
  
}

type Tag {
  id: ID! @id
  name: String! @unique
   
}

My technology stack is Typescript Apollo nexus-prisma and prisma and I have the following requirements:

*** I want a user to be able to create a category without creating a post first**

*** I want a user to be able to create a user without creating a post first**

*** I want a user to be able to create multiple tags without creating a post first**

So basically i want to keep all my relationships on the post table and when a user creates a post, they need to provide an author(user must be logged in), a category and multiple tags for the same post.

Also when I tried to make the name an array of strings in the Tag datamodel I couldn’t add any tags, mu mutation in the playground look like this:

    mutation {
  createTag(
    data: {name:["json","tyepscript","apollo"]}
    
  ) {
    id
    name
  }
}

Also I want to be able to filter the post after each of the 3 tables: author category and tag.

Thank you in advanced for any advice or guidelines you can provide, because I couldn’t find anything in documentation that describes this.