Skip to content

feat: add managed reverse edge support - #107

Merged
matthewmcneely merged 1 commit into
masterfrom
matthewmcneely/improve-reverse-edge-functionality
Jan 24, 2026
Merged

matthewmcneely merged 1 commit into
masterfrom
matthewmcneely/improve-reverse-edge-functionality

Conversation

@matthewmcneely

Copy link
Copy Markdown
Collaborator

This PR 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 explicitly.

See the new reverse_test.go for all the capabilities

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.
@matthewmcneely
matthewmcneely merged commit e2e2e7a into master Jan 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant