Skip to content

Commit cace4a6

Browse files
authored
avoid copying structures with embedded mutexs (#7571)
Fixes warning like this: assignment copies lock value to relationships: gorm.io/gorm/schema.Relationships contains sync.RWMutex
1 parent 7ceb0d9 commit cace4a6

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

generics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,12 @@ func (c chainG[T]) Preload(association string, query func(db PreloadBuilder) err
425425
relation, ok := db.Statement.Schema.Relationships.Relations[association]
426426
if !ok {
427427
if preloadFields := strings.Split(association, "."); len(preloadFields) > 1 {
428-
relationships := db.Statement.Schema.Relationships
428+
relationships := &db.Statement.Schema.Relationships
429429
for _, field := range preloadFields {
430430
var ok bool
431431
relation, ok = relationships.Relations[field]
432432
if ok {
433-
relationships = relation.FieldSchema.Relationships
433+
relationships = &relation.FieldSchema.Relationships
434434
} else {
435435
db.AddError(fmt.Errorf("relation %s not found", association))
436436
return nil

schema/schema_helper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"gorm.io/gorm/utils/tests"
1212
)
1313

14-
func checkSchema(t *testing.T, s *schema.Schema, v schema.Schema, primaryFields []string) {
14+
func checkSchema(t *testing.T, s *schema.Schema, v *schema.Schema, primaryFields []string) {
1515
t.Run("CheckSchema/"+s.Name, func(t *testing.T) {
1616
tests.AssertObjEqual(t, s, v, "Name", "Table")
1717

schema/schema_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestParseSchemaWithPointerFields(t *testing.T) {
4646

4747
func checkUserSchema(t *testing.T, user *schema.Schema) {
4848
// check schema
49-
checkSchema(t, user, schema.Schema{Name: "User", Table: "users"}, []string{"ID"})
49+
checkSchema(t, user, &schema.Schema{Name: "User", Table: "users"}, []string{"ID"})
5050

5151
// check fields
5252
fields := []schema.Field{
@@ -139,7 +139,7 @@ func TestParseSchemaWithAdvancedDataType(t *testing.T) {
139139
}
140140

141141
// check schema
142-
checkSchema(t, user, schema.Schema{Name: "AdvancedDataTypeUser", Table: "advanced_data_type_users"}, []string{"ID"})
142+
checkSchema(t, user, &schema.Schema{Name: "AdvancedDataTypeUser", Table: "advanced_data_type_users"}, []string{"ID"})
143143

144144
// check fields
145145
fields := []schema.Field{

0 commit comments

Comments
 (0)