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

Method Association

association.go:21–40  ·  view source on GitHub ↗
(column string)

Source from the content-addressed store, hash-verified

19}
20
21func (db *DB) Association(column string) *Association {
22 association := &Association{DB: db, Unscope: db.Statement.Unscoped}
23 table := db.Statement.Table
24
25 if association.Error = db.Statement.Parse(db.Statement.Model); association.Error == nil {
26 db.Statement.Table = table
27 association.Relationship = db.Statement.Schema.Relationships.Relations[column]
28
29 if association.Relationship == nil {
30 association.Error = fmt.Errorf("%w: %s", ErrUnsupportedRelation, column)
31 }
32
33 db.Statement.ReflectValue = reflect.ValueOf(db.Statement.Model)
34 for db.Statement.ReflectValue.Kind() == reflect.Ptr {
35 db.Statement.ReflectValue = db.Statement.ReflectValue.Elem()
36 }
37 }
38
39 return association
40}
41
42func (association *Association) Unscoped() *Association {
43 return &Association{

Calls 1

ParseMethod · 0.80