Skip to content

Commit 04d6097

Browse files
Adding example (#866)
1 parent 8f719c8 commit 04d6097

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

website/pages/en/subgraphs/developing/creating/ql-schema.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ type TokenBalance @entity {
160160
}
161161
```
162162

163+
Here is an example of how to write a mapping for a subgraph with reverse lookups:
164+
165+
```typescript
166+
let token = new Token(event.address) // Create Token
167+
token.save() // tokenBalances is derived automatically
168+
169+
let tokenBalance = new TokenBalance(event.address)
170+
tokenBalance.amount = BigInt.fromI32(0)
171+
tokenBalance.token = token.id // Reference stored here
172+
tokenBalance.save()
173+
```
174+
163175
#### Many-To-Many Relationships
164176

165177
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.

0 commit comments

Comments
 (0)