79149241

Date: 2024-11-01 19:51:29
Score: 0.5
Natty:
Report link

From another thread, I got this solution to do a recursive selectinload:

  child_select = selectinload(Parent.child)
  for _ in range(<depth>):
    child_select = child_select.selectinload(
      child_select.nodes)

  statement = select(Parent).filter(
    Parent.id == parent_id).options(child_select)
  result = await session.execute(statement)
  parent = result.scalars().first()
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Jon Hayden