github.com/duskeagle/pop@v4.10.1-0.20190417200916-92f2b794aab5+incompatible/belongs_to.go (about) 1 package pop 2 3 import ( 4 "fmt" 5 ) 6 7 // BelongsTo adds a "where" clause based on the "ID" of the 8 // "model" passed into it. 9 func (c *Connection) BelongsTo(model interface{}) *Query { 10 return Q(c).BelongsTo(model) 11 } 12 13 // BelongsToAs adds a "where" clause based on the "ID" of the 14 // "model" passed into it using an alias. 15 func (c *Connection) BelongsToAs(model interface{}, as string) *Query { 16 return Q(c).BelongsToAs(model, as) 17 } 18 19 // BelongsTo adds a "where" clause based on the "ID" of the 20 // "model" passed into it. 21 func (q *Query) BelongsTo(model interface{}) *Query { 22 m := &Model{Value: model} 23 q.Where(fmt.Sprintf("%s = ?", m.associationName()), m.ID()) 24 return q 25 } 26 27 // BelongsToAs adds a "where" clause based on the "ID" of the 28 // "model" passed into it, using an alias. 29 func (q *Query) BelongsToAs(model interface{}, as string) *Query { 30 m := &Model{Value: model} 31 q.Where(fmt.Sprintf("%s = ?", as), m.ID()) 32 return q 33 } 34 35 // BelongsToThrough adds a "where" clause that connects the "bt" model 36 // through the associated "thru" model. 37 func (c *Connection) BelongsToThrough(bt, thru interface{}) *Query { 38 return Q(c).BelongsToThrough(bt, thru) 39 } 40 41 // BelongsToThrough adds a "where" clause that connects the "bt" model 42 // through the associated "thru" model. 43 func (q *Query) BelongsToThrough(bt, thru interface{}) *Query { 44 q.belongsToThroughClauses = append(q.belongsToThroughClauses, belongsToThroughClause{ 45 BelongsTo: &Model{Value: bt}, 46 Through: &Model{Value: thru}, 47 }) 48 return q 49 }