MCPcopy
hub / github.com/tortoise/tortoise-orm / test_prefetch_nested

Function test_prefetch_nested

tests/test_prefetching.py:77–92  ·  view source on GitHub ↗
(db)

Source from the content-addressed store, hash-verified

75
76@pytest.mark.asyncio
77async def test_prefetch_nested(db):
78 tournament = await Tournament.create(name="tournament")
79 event = await Event.create(name="First", tournament=tournament)
80 await Event.create(name="Second", tournament=tournament)
81 team = await Team.create(name="1")
82 team_second = await Team.create(name="2")
83 await event.participants.add(team, team_second)
84 fetched_tournaments = (
85 await Tournament.all()
86 .prefetch_related(
87 Prefetch("events", queryset=Event.filter(name="First")),
88 Prefetch("events__participants", queryset=Team.filter(name="1")),
89 )
90 .first()
91 )
92 assert len(fetched_tournaments.events[0].participants) == 1
93
94
95@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 7

PrefetchClass · 0.90
addMethod · 0.80
createMethod · 0.45
firstMethod · 0.45
prefetch_relatedMethod · 0.45
allMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…