-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Report:
SaveDepth failed to save entity when you try to reverse relation with Link/Unlink function.
E.g. you have (node1)-[HAS_NODE]->(node2) and you wand to reverse relation to have (node1)<-[HAS_NODE]-(node2):
node2.UnlinkParent(node1)
node2.LinkChild(node1)
SaveDepth(node2) - error
Expected Behavior
After changing relation with Link/Unlink functions, SaveDepth function works without errors and relation is changed.
Current Behavior
SaveDepth gives failed to save in auto transaction, expected relationship deletions not equal to actual. Expected=2|Actual=1
Steps to Reproduce
Code example in the end.
- Use structure
type Node struct {
gogm.BaseUUIDNode
Name string `gogm:"name=name"`
Children []*Node `gogm:"direction=outgoing;relationship=HAS_NODE"`
Parents []*Node `gogm:"direction=incoming;relationship=HAS_NODE"`
}
- Create functions with
gogmcli - Create 2 nodes
- Add
node2as child fornode1 - Save
node2with depth 1 - Load
node2 - Remove parent from
node2and add children:
node2.UnlinkFromNodeOnFieldParents(parent)
node2..LinkToNodeOnFieldChildren(parent)
- Save
node2with depth 1.
Possible Solution
Environment
| Value | |
|---|---|
| Go Version | go version go1.18.3 windows/amd64 |
| GoGM Version | v2.3.6 |
| Neo4J Version | Version: 4.4.3 Edition: community |
| Operating System | Win10 x64 |
Would you be interested in tackling this issue
No
Additional info
n1 := &Node{Name: "n1"}
n2 := &Node{Name: "n2"}
n1.LinkToNodeOnFieldChildren(n2)
err = sess.SaveDepth(ctx, n1, 1)
if err != nil {
log.Err(err).Msg("")
return
}
n22 := &Node{}
err = sess.LoadDepth(ctx, n22, n2.UUID, 1)
if err != nil {
log.Err(err).Msg("")
return
}
fmt.Printf("Parents: %d\n", len(n22.Parents)) // 1
fmt.Printf("Children: %d\n", len(n22.Children)) // 0
parent := n22.Parents[0]
n22.UnlinkFromNodeOnFieldParents(parent)
n22.LinkToNodeOnFieldChildren(parent)
err = sess.SaveDepth(ctx, n22, 1)
// failed to save in auto transaction, expected relationship deletions not equal to actual. Expected=2|Actual=1
if err != nil {
log.Err(err).Msg("")
}
// Works fine if you save child and reload parent node between unlink/link
n22 = &Node{}
err = sess.LoadDepth(ctx, n22, n2.UUID, 1)
if err != nil {
log.Err(err).Msg("")
return
}
parent = n22.Parents[0]
err = n22.UnlinkFromNodeOnFieldParents(parent)
err = sess.SaveDepth(ctx, n22, 1)
if err != nil {
log.Err(err).Msg("")
}
err = sess.LoadDepth(ctx, parent, parent.UUID, 1)
if err != nil {
log.Err(err).Msg("")
}
n22.LinkToNodeOnFieldChildren(parent)
err = sess.SaveDepth(ctx, n22, 1)
if err != nil {
log.Err(err).Msg("")
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working