Skip to content

Commit 71781b1

Browse files
committed
fix: set foreign key reference automatically for belongs to associations
1 parent 6c3495d commit 71781b1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

repository.go

+5
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,14 @@ func (r repository) saveBelongsTo(cw contextWrapper, doc *Document, mutation *Mu
613613

614614
var (
615615
rField = assoc.ReferenceField()
616+
rValue = assoc.ReferenceValue()
616617
fValue = assoc.ForeignValue()
617618
)
618619

620+
if rValue == 0 {
621+
rValue = fValue
622+
}
623+
619624
mutation.Add(Set(rField, fValue))
620625
doc.SetValue(rField, fValue)
621626
}

0 commit comments

Comments
 (0)