Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding example #866

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions website/pages/en/subgraphs/developing/creating/ql-schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ type TokenBalance @entity {
}
```

Here is an example of how to write a mapping for a subgraph with reverse lookups:

```typescript
let token = new Token(event.address) // Create Token
token.save() // tokenBalances is derived automatically

let tokenBalance = new TokenBalance(event.address)
tokenBalance.amount = BigInt.fromI32(0)
tokenBalance.token = token.id // Reference stored here
tokenBalance.save()
```

#### Many-To-Many Relationships

For many-to-many relationships, such as users that each may belong to any number of organizations, the most straightforward, but generally not the most performant, way to model the relationship is as an array in each of the two entities involved. If the relationship is symmetric, only one side of the relationship needs to be stored and the other side can be derived.
Expand Down