在 amplify graphql 中添加多对多连接

Add many to many connection in amplify graphql

我有一个耗时的问题,不知道我还能测试什么。 这是有效的,但我需要在 Recruiter 中定位一个数组。但是后来我有一个多对多的连接并且没有任何工作了。有什么好的方法可以解决吗? 这是我的代码:

type Position @model @auth(rules: []) {
  id: ID!
  title: String!
  candidates: [Candidate]! @connection(name: "PositionCandidates")
  interestedRecruiters: [Recruiter]! @connection(name: "PositionRecruiter")
}
type Candidate @model @auth(rules: []) {
  id: ID!
  firstname: String!
  lastname: String!
  email: AWSEmail!
  birthday: AWSDate!
  position: Position! @connection(name: "PositionCandidates")
}
type Recruiter @model @auth(rules: []) {
  id: ID!
  firstname: String!
  lastname: String!
  email: AWSEmail!
  birthday: AWSDate!
  positions: Position! @connection(name: "PositionRecruiter")
}

谢谢!

要使用 amplify/app 同步进行多对多连接,您必须创建一个 'Join' table(类型)。您可以将连接 table 视为存储连接的 table。

从你的例子中我没有完全理解你想要的结果,所以我会尝试用另一个例子来解释:

假设您有一个系统,其中多个用户可以是一个文档的创建者,一个用户也可以是多个文档的创建者之一。为此,您必须创建三个 dynamoDb tables(或者三种类型是模式)。

type User @model {
  id: ID!
  name: String
  documents: [UserDocument] @connection(name: "UserDocumentConnection")
}

type Document @model {
   id: ID!
   title: String
   content: String
   users: [UserDocument] @connection(name: "DocumentUserConnection")
}

type UserDocument @model {
   id: ID!
   user: User @connection(name: "UserDocumentConnection")
   document: Document @connection(name: "DocumentUserConnection")
}

然后你有一个包含所有用户的table,一个包含你所有文档的table,以及一个包含用户和文档之间所有连接的table。

假设您有一个正在创建新文档的用户。然后你首先创建文档,然后当它被创建并且你已经从 appsync 收到文档的新 id 返回文档时,你必须在 UserDocument table 中创建一个新对象,包含用户和文档的 ID。然后,您还可以通过向 UserDocument table.

添加更多项目来在文档中添加更多用户

我希望这能帮助你走上正确的前进道路。