Allow selection of all columns in a leaf preload by not specifying any column

This commit is contained in:
Diego Sogari 2023-04-09 15:27:49 -03:00
parent 17358d66b6
commit 89a266addf
No known key found for this signature in database
GPG Key ID: 03A9A337B873A022
3 changed files with 14 additions and 3 deletions

View File

@ -98,6 +98,10 @@ func (statement *Statement) genColumnStr() string {
continue continue
} }
if col.Association != nil {
continue
}
if buf.Len() != 0 { if buf.Len() != 0 {
buf.WriteString(", ") buf.WriteString(", ")
} }

View File

@ -134,9 +134,14 @@ func (node *PreloadTreeNode) compute(session *Session, ownMap, pruneMap reflect.
} }
refMap := node.association.MakeRefMap() refMap := node.association.MakeRefMap()
preloadSession := session.Engine().Cols(node.extraCols...).Where(cond) preloadSession := session.Engine().Where(cond)
if node.preload != nil { if node.preload != nil {
preloadSession.Cols(node.preload.cols...).Where(node.preload.cond) if len(node.preload.cols) > 0 {
preloadSession.Cols(node.extraCols...).Cols(node.preload.cols...)
}
preloadSession.Where(node.preload.cond)
} else {
preloadSession.Cols(node.extraCols...)
} }
if err := preloadSession.Find(refMap.Interface()); err != nil { if err := preloadSession.Find(refMap.Interface()); err != nil {
return err return err

View File

@ -124,10 +124,12 @@ insert into employee_indication values (1,2), (1,3), (2,3), (2,4), (2,5), (3,5),
Subordinates: []*Employee{ Subordinates: []*Employee{
{ {
Id: 3, Id: 3,
Name: "Alice",
ManagerId: &[]int64{1}[0], ManagerId: &[]int64{1}[0],
IndicatedBy: []*Employee{ IndicatedBy: []*Employee{
{ {
Id: 1, Id: 1,
Name: "John",
Indications: []*Employee{ Indications: []*Employee{
{ {
Id: 2, Id: 2,