(ctx context.Context, query *EntityQuery, nodes []*File, init func(*File), assign func(*File, *Entity))
| 853 | return nil |
| 854 | } |
| 855 | func (fq *FileQuery) loadEntities(ctx context.Context, query *EntityQuery, nodes []*File, init func(*File), assign func(*File, *Entity)) error { |
| 856 | edgeIDs := make([]driver.Value, len(nodes)) |
| 857 | byID := make(map[int]*File) |
| 858 | nids := make(map[int]map[*File]struct{}) |
| 859 | for i, node := range nodes { |
| 860 | edgeIDs[i] = node.ID |
| 861 | byID[node.ID] = node |
| 862 | if init != nil { |
| 863 | init(node) |
| 864 | } |
| 865 | } |
| 866 | query.Where(func(s *sql.Selector) { |
| 867 | joinT := sql.Table(file.EntitiesTable) |
| 868 | s.Join(joinT).On(s.C(entity.FieldID), joinT.C(file.EntitiesPrimaryKey[1])) |
| 869 | s.Where(sql.InValues(joinT.C(file.EntitiesPrimaryKey[0]), edgeIDs...)) |
| 870 | columns := s.SelectedColumns() |
| 871 | s.Select(joinT.C(file.EntitiesPrimaryKey[0])) |
| 872 | s.AppendSelect(columns...) |
| 873 | s.SetDistinct(false) |
| 874 | }) |
| 875 | if err := query.prepareQuery(ctx); err != nil { |
| 876 | return err |
| 877 | } |
| 878 | qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { |
| 879 | return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { |
| 880 | assign := spec.Assign |
| 881 | values := spec.ScanValues |
| 882 | spec.ScanValues = func(columns []string) ([]any, error) { |
| 883 | values, err := values(columns[1:]) |
| 884 | if err != nil { |
| 885 | return nil, err |
| 886 | } |
| 887 | return append([]any{new(sql.NullInt64)}, values...), nil |
| 888 | } |
| 889 | spec.Assign = func(columns []string, values []any) error { |
| 890 | outValue := int(values[0].(*sql.NullInt64).Int64) |
| 891 | inValue := int(values[1].(*sql.NullInt64).Int64) |
| 892 | if nids[inValue] == nil { |
| 893 | nids[inValue] = map[*File]struct{}{byID[outValue]: {}} |
| 894 | return assign(columns[1:], values[1:]) |
| 895 | } |
| 896 | nids[inValue][byID[outValue]] = struct{}{} |
| 897 | return nil |
| 898 | } |
| 899 | }) |
| 900 | }) |
| 901 | neighbors, err := withInterceptors[[]*Entity](ctx, query, qr, query.inters) |
| 902 | if err != nil { |
| 903 | return err |
| 904 | } |
| 905 | for _, n := range neighbors { |
| 906 | nodes, ok := nids[n.ID] |
| 907 | if !ok { |
| 908 | return fmt.Errorf(`unexpected "entities" node returned %v`, n.ID) |
| 909 | } |
| 910 | for kn := range nodes { |
| 911 | assign(kn, n) |
| 912 | } |
no test coverage detected