One to Many properties relationship

Hi there, I have a lending oriented schema like so:

type Loan {
  id: ID!
  value: String!
  currency: String!
  lender: Member!
  borrower: Member!
}

type Member {
  id: ID!
  cordaNodeName: String
  loans: [Loan] 
}

Where

  1. A member can have many loans (fine)
  2. 2 members are part of the same loan (lender and borrower)

How can I model an inverse relationship here between the two properties on one entity and the single property on the other one?

Could one put two properties inside the @hasInverse, for example?

loans [Loan] @hasInverse(field: lender, borrower)

I see I could actually do outLoans and inLoans with two separate [Loan] lists

1 Like

This is possible, (at least it was. It is undocumented, and I am no longer using. Not sure if there are tests under the hood to check for this functionality, so I would not use it in production myself)
See:

I have found that it can lead to a big problem with trying to do some kind of indexing on the edges. I just stopped trying to do these “three-way” relationships and just stick to two-way relationships.

type Loan {
  id: ID!
  value: String!
  currency: String!
  lender: Member!
  borrower: Member!
}

type Member {
  id: ID!
  cordaNodeName: String
  borrowed: [Loan] @hasInverse(field: "borrower")
  lended: [Loan] @hasInverse(field: "lender")
}

When possible try to name the edges more appropiately, you will thank yourself later when trying to remember which was an inLoan and outLoan actually go. lended and borrowed makes more sense as the edge names in this context.

Perfect answer, thank you kindly @amaster507 :slight_smile:

1 Like

TIL too

1 Like