Wrong code example on Many-To-Many relationship

The following code that can be found in the documentation seems to be wrong:

type Organization @entity {
  id: ID!
  name: String!
  members: [UserOrganization]! @derivedFrom(field: "user")
}

type User @entity {
  id: ID!
  name: String!
  organizations: [UserOrganization!] @derivedFrom(field: "organization")
}

type UserOrganization @entity {
  id: ID!   # Set to `${user.id}-${organization.id}`
  user: User!
  organization: Organization!
}

And should have the @derivedFrom parameter switched like this:

type Organization @entity {
  id: ID!
  name: String!
  members: [UserOrganization]! @derivedFrom(field: "organization")
}

type User @entity {
  id: ID!
  name: String!
  organizations: [UserOrganization!] @derivedFrom(field: "user")
}

type UserOrganization @entity {
  id: ID!   # Set to `${user.id}-${organization.id}`
  user: User!
  organization: Organization!
}
1 Like

Yeah, I think you’re completely right.

It’s probably an honest mistake, since it’s quite easy to get confused when deriving arrays from entity links :slight_smile:

1 Like