feat: add managed reverse edge support - #107
Merged
matthewmcneely merged 1 commit intoJan 24, 2026
Merged
Conversation
Allows defining reverse edges on parent structs using `json:"~predicate"`
combined with `dgraph:"reverse"`. On mutation, dgman automatically creates
forward edges on children pointing to the parent.
Changes:
- schema.go: Add ManagedReverse/ForwardPredicate fields, detect ~predicate + reverse tag
- mutate.go: Create forward edge mutations on children for managed reverse edges
- query.go: Generate explicit reverse edge blocks in All() queries
Usage:
type Department struct {
Courses []*Course `json:"~in_department,omitempty" dgraph:"reverse"`
}
type Course struct {
InDepartment *Department `json:"in_department,omitempty" dgraph:"reverse"`
}
Mutating Department with embedded Courses now automatically sets
Course.in_department edges, and queries expand reverse edges correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR allows defining reverse edges on parent structs using
json:"~predicate"combined withdgraph:"reverse". On mutation, dgman automatically creates forward edges on children pointing to the parent.Changes:
Usage:
Mutating Department with embedded Courses now automatically sets Course.in_department edges, and queries expand reverse edges explicitly.
See the new
reverse_test.gofor all the capabilities