fix: nested preload with join panic when find (#6877)

This commit is contained in:
black-06
2024-03-09 21:27:19 +08:00
committed by GitHub
parent c4c9aa45e3
commit e4e23d26d2
2 changed files with 27 additions and 4 deletions
+10
View File
@@ -8,6 +8,8 @@ import (
"sync"
"testing"
"github.com/stretchr/testify/require"
"gorm.io/gorm"
"gorm.io/gorm/clause"
. "gorm.io/gorm/utils/tests"
@@ -362,6 +364,14 @@ func TestNestedPreloadWithNestedJoin(t *testing.T) {
t.Errorf("failed to find value, got err: %v", err)
}
AssertEqual(t, find2, value)
var finds []Value
err = DB.Joins("Nested.Join").Joins("Nested").Preload("Nested.Preloads").Find(&finds).Error
if err != nil {
t.Errorf("failed to find value, got err: %v", err)
}
require.Len(t, finds, 1)
AssertEqual(t, finds[0], value)
}
func TestEmbedPreload(t *testing.T) {