MCPcopy
hub / github.com/go-gorm/gorm / AfterQuery

Function AfterQuery

callbacks/query.go:298–314  ·  view source on GitHub ↗
(db *gorm.DB)

Source from the content-addressed store, hash-verified

296}
297
298func AfterQuery(db *gorm.DB) {
299 // clear the joins after query because preload need it
300 if v, ok := db.Statement.Clauses["FROM"].Expression.(clause.From); ok {
301 fromClause := db.Statement.Clauses["FROM"]
302 fromClause.Expression = clause.From{Tables: v.Tables, Joins: utils.RTrimSlice(v.Joins, len(db.Statement.Joins))} // keep the original From Joins
303 db.Statement.Clauses["FROM"] = fromClause
304 }
305 if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && db.Statement.Schema.AfterFind && db.RowsAffected > 0 {
306 callMethod(db, func(value interface{}, tx *gorm.DB) bool {
307 if i, ok := value.(AfterFindInterface); ok {
308 db.AddError(i.AfterFind(tx))
309 return true
310 }
311 return false
312 })
313 }
314}

Callers

nothing calls this directly

Calls 4

RTrimSliceFunction · 0.92
callMethodFunction · 0.85
AddErrorMethod · 0.65
AfterFindMethod · 0.65

Tested by

no test coverage detected