Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions generics_join_as_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"testing"

"gorm.io/gorm"
"gorm.io/gorm/clause"
)

func TestGenericsJoins(t *testing.T) {
dbg := DB.Session(&gorm.Session{DryRun: true})
db := gorm.G[User](dbg)

q := db.Joins(clause.LeftJoin.AssociationFrom("Company", gorm.G[Company](dbg)).As("t"),
func(j gorm.JoinBuilder, joinTable clause.Table, curTable clause.Table) error {
j.Where("?.\"name\" = ?", joinTable, "GenericsCompany")
return nil
},
).Where(map[string]any{"name": "GenericsJoins_2"})

stmt := &gorm.Statement{DB: dbg}
q.Build(stmt)

sql := stmt.SQL.String()
t.Logf("GENERATED SQL:\n%s", sql)
}
Loading