| 550 | return nil |
| 551 | } |
| 552 | func (eq *EntityQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Entity, init func(*Entity), assign func(*Entity, *User)) error { |
| 553 | ids := make([]int, 0, len(nodes)) |
| 554 | nodeids := make(map[int][]*Entity) |
| 555 | for i := range nodes { |
| 556 | fk := nodes[i].CreatedBy |
| 557 | if _, ok := nodeids[fk]; !ok { |
| 558 | ids = append(ids, fk) |
| 559 | } |
| 560 | nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 561 | } |
| 562 | if len(ids) == 0 { |
| 563 | return nil |
| 564 | } |
| 565 | query.Where(user.IDIn(ids...)) |
| 566 | neighbors, err := query.All(ctx) |
| 567 | if err != nil { |
| 568 | return err |
| 569 | } |
| 570 | for _, n := range neighbors { |
| 571 | nodes, ok := nodeids[n.ID] |
| 572 | if !ok { |
| 573 | return fmt.Errorf(`unexpected foreign-key "created_by" returned %v`, n.ID) |
| 574 | } |
| 575 | for i := range nodes { |
| 576 | assign(nodes[i], n) |
| 577 | } |
| 578 | } |
| 579 | return nil |
| 580 | } |
| 581 | func (eq *EntityQuery) loadStoragePolicy(ctx context.Context, query *StoragePolicyQuery, nodes []*Entity, init func(*Entity), assign func(*Entity, *StoragePolicy)) error { |
| 582 | ids := make([]int, 0, len(nodes)) |
| 583 | nodeids := make(map[int][]*Entity) |