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

Method Attrs

chainable_api.go:418–422  ·  view source on GitHub ↗

Attrs provide attributes used in [FirstOrCreate] or [FirstOrInit] Attrs only adds attributes if the record is not found. // assign an email if the record is not found db.Where(User{Name: "non_existing"}).Attrs(User{Email: "fake@fake.org"}).FirstOrInit(&user) // user -> User{Name: "non_existing"

(attrs ...interface{})

Source from the content-addressed store, hash-verified

416// [FirstOrCreate]: https://gorm.io/docs/advanced_query.html#FirstOrCreate
417// [FirstOrInit]: https://gorm.io/docs/advanced_query.html#FirstOrInit
418func (db *DB) Attrs(attrs ...interface{}) (tx *DB) {
419 tx = db.getInstance()
420 tx.Statement.attrs = attrs
421 return
422}
423
424// Assign provide attributes used in [FirstOrCreate] or [FirstOrInit]
425//

Callers 2

TestFindOrInitializeFunction · 0.80
TestFindOrCreateFunction · 0.80

Calls 1

getInstanceMethod · 0.95

Tested by 2

TestFindOrInitializeFunction · 0.64
TestFindOrCreateFunction · 0.64