| 402 | } |
| 403 | |
| 404 | func (_q *MetaQuery) loadOwner(ctx context.Context, query *AlertQuery, nodes []*Meta, init func(*Meta), assign func(*Meta, *Alert)) error { |
| 405 | ids := make([]int, 0, len(nodes)) |
| 406 | nodeids := make(map[int][]*Meta) |
| 407 | for i := range nodes { |
| 408 | fk := nodes[i].AlertMetas |
| 409 | if _, ok := nodeids[fk]; !ok { |
| 410 | ids = append(ids, fk) |
| 411 | } |
| 412 | nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 413 | } |
| 414 | if len(ids) == 0 { |
| 415 | return nil |
| 416 | } |
| 417 | query.Where(alert.IDIn(ids...)) |
| 418 | neighbors, err := query.All(ctx) |
| 419 | if err != nil { |
| 420 | return err |
| 421 | } |
| 422 | for _, n := range neighbors { |
| 423 | nodes, ok := nodeids[n.ID] |
| 424 | if !ok { |
| 425 | return fmt.Errorf(`unexpected foreign-key "alert_metas" returned %v`, n.ID) |
| 426 | } |
| 427 | for i := range nodes { |
| 428 | assign(nodes[i], n) |
| 429 | } |
| 430 | } |
| 431 | return nil |
| 432 | } |
| 433 | |
| 434 | func (_q *MetaQuery) sqlCount(ctx context.Context) (int, error) { |
| 435 | _spec := _q.querySpec() |