| 484 | return nil |
| 485 | } |
| 486 | func (sq *ShareQuery) loadFile(ctx context.Context, query *FileQuery, nodes []*Share, init func(*Share), assign func(*Share, *File)) error { |
| 487 | ids := make([]int, 0, len(nodes)) |
| 488 | nodeids := make(map[int][]*Share) |
| 489 | for i := range nodes { |
| 490 | if nodes[i].file_shares == nil { |
| 491 | continue |
| 492 | } |
| 493 | fk := *nodes[i].file_shares |
| 494 | if _, ok := nodeids[fk]; !ok { |
| 495 | ids = append(ids, fk) |
| 496 | } |
| 497 | nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 498 | } |
| 499 | if len(ids) == 0 { |
| 500 | return nil |
| 501 | } |
| 502 | query.Where(file.IDIn(ids...)) |
| 503 | neighbors, err := query.All(ctx) |
| 504 | if err != nil { |
| 505 | return err |
| 506 | } |
| 507 | for _, n := range neighbors { |
| 508 | nodes, ok := nodeids[n.ID] |
| 509 | if !ok { |
| 510 | return fmt.Errorf(`unexpected foreign-key "file_shares" returned %v`, n.ID) |
| 511 | } |
| 512 | for i := range nodes { |
| 513 | assign(nodes[i], n) |
| 514 | } |
| 515 | } |
| 516 | return nil |
| 517 | } |
| 518 | |
| 519 | func (sq *ShareQuery) sqlCount(ctx context.Context) (int, error) { |
| 520 | _spec := sq.querySpec() |