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

Method buildCondition

association.go:608–636  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

606}
607
608func (association *Association) buildCondition() *DB {
609 var (
610 queryConds = association.Relationship.ToQueryConditions(association.DB.Statement.Context, association.DB.Statement.ReflectValue)
611 modelValue = reflect.New(association.Relationship.FieldSchema.ModelType).Interface()
612 tx = association.DB.Model(modelValue)
613 )
614
615 if association.Relationship.JoinTable != nil {
616 if !tx.Statement.Unscoped && len(association.Relationship.JoinTable.QueryClauses) > 0 {
617 joinStmt := Statement{DB: tx, Context: tx.Statement.Context, Schema: association.Relationship.JoinTable, Table: association.Relationship.JoinTable.Table, Clauses: map[string]clause.Clause{}}
618 for _, queryClause := range association.Relationship.JoinTable.QueryClauses {
619 joinStmt.AddClause(queryClause)
620 }
621 joinStmt.Build("WHERE")
622 if len(joinStmt.SQL.String()) > 0 {
623 tx.Clauses(clause.Expr{SQL: strings.Replace(joinStmt.SQL.String(), "WHERE ", "", 1), Vars: joinStmt.Vars})
624 }
625 }
626
627 tx = tx.Session(&Session{QueryFields: true}).Clauses(clause.From{Joins: []clause.Join{{
628 Table: clause.Table{Name: association.Relationship.JoinTable.Table},
629 ON: clause.Where{Exprs: queryConds},
630 }}})
631 } else {
632 tx.Clauses(clause.Where{Exprs: queryConds})
633 }
634
635 return tx
636}
637
638func expandValues(values ...any) (results []any) {
639 appendToResult := func(rv reflect.Value) {

Callers 2

FindMethod · 0.95
CountMethod · 0.95

Calls 9

AddClauseMethod · 0.95
BuildMethod · 0.95
ToQueryConditionsMethod · 0.80
ModelMethod · 0.80
ClausesMethod · 0.80
SessionMethod · 0.80
NewMethod · 0.65
ReplaceMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected