FindFirstRecordByData returns the first found record matching the provided key-value pair.
(collectionModelOrIdentifier any, key string, value any)
| 314 | // FindFirstRecordByData returns the first found record matching |
| 315 | // the provided key-value pair. |
| 316 | func (app *BaseApp) FindFirstRecordByData(collectionModelOrIdentifier any, key string, value any) (*Record, error) { |
| 317 | collection, err := getCollectionByModelOrIdentifier(app, collectionModelOrIdentifier) |
| 318 | if err != nil { |
| 319 | return nil, err |
| 320 | } |
| 321 | |
| 322 | field := collection.Fields.GetByName(key) |
| 323 | if field == nil { |
| 324 | return nil, errors.New("invalid or missing field " + key) |
| 325 | } |
| 326 | |
| 327 | record := &Record{} |
| 328 | |
| 329 | err = app.RecordQuery(collection). |
| 330 | AndWhere(dbx.HashExp{inflector.Columnify(key): value}). |
| 331 | Limit(1). |
| 332 | One(record) |
| 333 | if err != nil { |
| 334 | return nil, err |
| 335 | } |
| 336 | |
| 337 | return record, nil |
| 338 | } |
| 339 | |
| 340 | // FindRecordsByFilter returns limit number of records matching the |
| 341 | // provided string filter. |
nothing calls this directly
no test coverage detected