| 19 | } |
| 20 | |
| 21 | func (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 | |
| 42 | func (association *Association) Unscoped() *Association { |
| 43 | return &Association{ |