GraphQl @manyToMany usage?

Viewed 303

I work with Amplify/graphQl transformer V2, I try to do the same things like the official documentation of Amplify : https://docs.amplify.aws/cli/graphql/data-modeling/#many-to-many-relationship

So in the part of @manyToMany relationship, I understand that the relational Table generated automatically and in amplify studio I found all queries and mutaions... of this table.

My question is how can I add some fields in this table (relationalTable).

N.B : I'm using the same example of the documentation : https://docs.amplify.aws/cli/graphql/data-modeling/#many-to-many-relationship so how can I add for example the field City in the PostTags table ?

type Post @model {
  id: ID!
  title: String!
  content: String
  tags: [Tag] @manyToMany(relationName: "PostTags")
}

type Tag @model {
  id: ID!
  label: String!
  posts: [Post] @manyToMany(relationName: "PostTags")
}
1 Answers

So, to solve this problem I changed the logic to work with @HasOne, instead of @ManyToMany

type Post @model {
  id: ID!
  title: String!
  content: String
}

type Tag @model {
  id: ID!
  label: String!
}

// Relational Table

type PostTag @model {
  id: ID!
  tag: Tag@hasOne
  post: Post@hasOne

  // Other attributes here
}
Related