| 543 | } |
| 544 | |
| 545 | func (_q *AlertQuery) loadOwner(ctx context.Context, query *MachineQuery, nodes []*Alert, init func(*Alert), assign func(*Alert, *Machine)) error { |
| 546 | ids := make([]int, 0, len(nodes)) |
| 547 | nodeids := make(map[int][]*Alert) |
| 548 | for i := range nodes { |
| 549 | if nodes[i].machine_alerts == nil { |
| 550 | continue |
| 551 | } |
| 552 | fk := *nodes[i].machine_alerts |
| 553 | if _, ok := nodeids[fk]; !ok { |
| 554 | ids = append(ids, fk) |
| 555 | } |
| 556 | nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 557 | } |
| 558 | if len(ids) == 0 { |
| 559 | return nil |
| 560 | } |
| 561 | query.Where(machine.IDIn(ids...)) |
| 562 | neighbors, err := query.All(ctx) |
| 563 | if err != nil { |
| 564 | return err |
| 565 | } |
| 566 | for _, n := range neighbors { |
| 567 | nodes, ok := nodeids[n.ID] |
| 568 | if !ok { |
| 569 | return fmt.Errorf(`unexpected foreign-key "machine_alerts" returned %v`, n.ID) |
| 570 | } |
| 571 | for i := range nodes { |
| 572 | assign(nodes[i], n) |
| 573 | } |
| 574 | } |
| 575 | return nil |
| 576 | } |
| 577 | func (_q *AlertQuery) loadDecisions(ctx context.Context, query *DecisionQuery, nodes []*Alert, init func(*Alert), assign func(*Alert, *Decision)) error { |
| 578 | fks := make([]driver.Value, 0, len(nodes)) |
| 579 | nodeids := make(map[int]*Alert) |