| 706 | } |
| 707 | |
| 708 | func (fq *FileQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*File, init func(*File), assign func(*File, *User)) error { |
| 709 | ids := make([]int, 0, len(nodes)) |
| 710 | nodeids := make(map[int][]*File) |
| 711 | for i := range nodes { |
| 712 | fk := nodes[i].OwnerID |
| 713 | if _, ok := nodeids[fk]; !ok { |
| 714 | ids = append(ids, fk) |
| 715 | } |
| 716 | nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 717 | } |
| 718 | if len(ids) == 0 { |
| 719 | return nil |
| 720 | } |
| 721 | query.Where(user.IDIn(ids...)) |
| 722 | neighbors, err := query.All(ctx) |
| 723 | if err != nil { |
| 724 | return err |
| 725 | } |
| 726 | for _, n := range neighbors { |
| 727 | nodes, ok := nodeids[n.ID] |
| 728 | if !ok { |
| 729 | return fmt.Errorf(`unexpected foreign-key "owner_id" returned %v`, n.ID) |
| 730 | } |
| 731 | for i := range nodes { |
| 732 | assign(nodes[i], n) |
| 733 | } |
| 734 | } |
| 735 | return nil |
| 736 | } |
| 737 | func (fq *FileQuery) loadStoragePolicies(ctx context.Context, query *StoragePolicyQuery, nodes []*File, init func(*File), assign func(*File, *StoragePolicy)) error { |
| 738 | ids := make([]int, 0, len(nodes)) |
| 739 | nodeids := make(map[int][]*File) |