| 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) |
| 584 | for i := range nodes { |
| 585 | fk := nodes[i].StoragePolicyEntities |
| 586 | if _, ok := nodeids[fk]; !ok { |
| 587 | ids = append(ids, fk) |
| 588 | } |
| 589 | nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 590 | } |
| 591 | if len(ids) == 0 { |
| 592 | return nil |
| 593 | } |
| 594 | query.Where(storagepolicy.IDIn(ids...)) |
| 595 | neighbors, err := query.All(ctx) |
| 596 | if err != nil { |
| 597 | return err |
| 598 | } |
| 599 | for _, n := range neighbors { |
| 600 | nodes, ok := nodeids[n.ID] |
| 601 | if !ok { |
| 602 | return fmt.Errorf(`unexpected foreign-key "storage_policy_entities" returned %v`, n.ID) |
| 603 | } |
| 604 | for i := range nodes { |
| 605 | assign(nodes[i], n) |
| 606 | } |
| 607 | } |
| 608 | return nil |
| 609 | } |
| 610 | |
| 611 | func (eq *EntityQuery) sqlCount(ctx context.Context) (int, error) { |
| 612 | _spec := eq.querySpec() |