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

Function test_prefetch_object

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

Source from the content-addressed store, hash-verified

21
22@pytest.mark.asyncio
23async def test_prefetch_object(db):
24 tournament = await Tournament.create(name="tournament")
25 await Event.create(name="First", tournament=tournament)
26 await Event.create(name="Second", tournament=tournament)
27 tournament_with_filtered = (
28 await Tournament.all()
29 .prefetch_related(Prefetch("events", queryset=Event.filter(name="First")))
30 .first()
31 )
32 tournament = await Tournament.first().prefetch_related("events")
33 assert len(tournament_with_filtered.events) == 1
34 assert len(tournament.events) == 2
35
36
37@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 6

PrefetchClass · 0.90
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…