()
| 70 | |
| 71 | |
| 72 | async def run(): |
| 73 | await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]}) |
| 74 | await Tortoise.generate_schemas() |
| 75 | |
| 76 | root = await Employee.create(name="Root") |
| 77 | loose = await Employee.create(name="Loose") |
| 78 | _1 = await Employee.create(name="1. First H1", manager=root) |
| 79 | _2 = await Employee.create(name="2. Second H1", manager=root) |
| 80 | _1_1 = await Employee.create(name="1.1. First H2", manager=_1) |
| 81 | _1_1_1 = await Employee.create(name="1.1.1. First H3", manager=_1_1) |
| 82 | _2_1 = await Employee.create(name="2.1. Second H2", manager=_2) |
| 83 | _2_2 = await Employee.create(name="2.2. Third H2", manager=_2) |
| 84 | |
| 85 | await _1.talks_to.add(_2, _1_1_1, loose) |
| 86 | await _2_1.gets_talked_to.add(_2_2, _1_1, loose) |
| 87 | |
| 88 | # Evaluated off creation objects |
| 89 | print(await loose.full_hierarchy__fetch_related()) |
| 90 | print(await root.full_hierarchy__async_for()) |
| 91 | print(await root.full_hierarchy__fetch_related()) |
| 92 | |
| 93 | # Evaluated off new objects → Result is identical |
| 94 | root2 = await Employee.get(name="Root") |
| 95 | loose2 = await Employee.get(name="Loose") |
| 96 | print(await loose2.full_hierarchy__fetch_related()) |
| 97 | print(await root2.full_hierarchy__async_for()) |
| 98 | print(await root2.full_hierarchy__fetch_related()) |
| 99 | |
| 100 | |
| 101 | if __name__ == "__main__": |
no test coverage detected