Question regarding relation between models

Hi! I just want to be sure I understand. Let’s say I have two models, Profile and Wallet.

Profile.gql

type Profile @createModel(accountRelation: SINGLE, description: "Profile") {
  email: String! @string(minLength: 5, maxLength: 255)
}

And Wallet.gql

type OamoProfile @loadModel(id: "$ROFILE_ID") {
  id: ID!
}

type Wallet @createModel(accountRelation: LIST, description: "This is a list of wallet owned by a user") {
  address: String! @string(minLength: 1, maxLength: 100)
  profileId: StreamID! @documentReference(model: "Profile")
  profile: Profile! @relationDocument(property: "profileId")
}

I want to confirm that I don’t need this third file to illustrate a relation (I assumed I needed it) since the relation is already written in the models above.

ProfileWallet.gql

type Wallet @loadModel(id: "$WALLET_ID") {
  id: ID!
}

type Profile @loadModel(id: "$PROFILE_ID") {
  wallets: [Wallet] @relationFrom(model: "Wallet", property: "profileId")`
1 Like

Hi,

The relation is defined in your Wallet model, so indeed you don’t need the third file. What your third file contains is a view from the profile to the related wallets, not the relation itself.

1 Like