Remove the `NoPrune` method
This commit is contained in:
parent
4f8ee6f919
commit
17358d66b6
15
preload.go
15
preload.go
|
@ -10,10 +10,9 @@ import (
|
||||||
|
|
||||||
// Preload is the representation of an association preload
|
// Preload is the representation of an association preload
|
||||||
type Preload struct {
|
type Preload struct {
|
||||||
path []string
|
path []string
|
||||||
cols []string
|
cols []string
|
||||||
cond builder.Cond
|
cond builder.Cond
|
||||||
noPrune bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPreload creates a new preload with the specified path
|
// NewPreload creates a new preload with the specified path
|
||||||
|
@ -36,12 +35,6 @@ func (p *Preload) Where(cond builder.Cond) *Preload {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoPrune sets a flag to avoid pruning empty associations
|
|
||||||
func (p *Preload) NoPrune() *Preload {
|
|
||||||
p.noPrune = true
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// PreloadTreeNode is a tree node for the association preloads
|
// PreloadTreeNode is a tree node for the association preloads
|
||||||
type PreloadTreeNode struct {
|
type PreloadTreeNode struct {
|
||||||
preload *Preload
|
preload *Preload
|
||||||
|
@ -150,7 +143,7 @@ func (node *PreloadTreeNode) compute(session *Session, ownMap, pruneMap reflect.
|
||||||
}
|
}
|
||||||
|
|
||||||
var refPruneMap reflect.Value
|
var refPruneMap reflect.Value
|
||||||
if len(node.children) > 0 && !(node.preload != nil && (len(node.preload.cols) > 0 || node.preload.noPrune)) {
|
if len(node.children) > 0 && !(node.preload != nil && len(node.preload.cols) > 0) {
|
||||||
refPruneMap = reflect.MakeMap(reflect.MapOf(refMap.Type().Key(), reflect.TypeOf(true)))
|
refPruneMap = reflect.MakeMap(reflect.MapOf(refMap.Type().Key(), reflect.TypeOf(true)))
|
||||||
refIter := refMap.MapRange()
|
refIter := refMap.MapRange()
|
||||||
for refIter.Next() {
|
for refIter.Next() {
|
||||||
|
|
|
@ -62,7 +62,7 @@ insert into employee_indication values (1,2), (1,3), (2,3), (2,4), (2,5), (3,5),
|
||||||
var employee Employee
|
var employee Employee
|
||||||
_, err = engine.Preloads(
|
_, err = engine.Preloads(
|
||||||
engine.Preload("Indications.Buddy").Cols("name"),
|
engine.Preload("Indications.Buddy").Cols("name"),
|
||||||
engine.Preload("Indications").NoPrune(),
|
engine.Preload("Indications").Cols("id"),
|
||||||
).Cols("name").Where(builder.Eq{"id": 2}).Get(&employee)
|
).Cols("name").Where(builder.Eq{"id": 2}).Get(&employee)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue