From a6aff36585838e1cedab16b3dfc384be231dc6b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eahin=20Akkaya?= Date: Mon, 5 Aug 2024 10:07:49 +0300 Subject: [PATCH] Fix an error --- ...lly-load-sqlalchemy-model-relationships-in-fastapi.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/_posts/2024-08-04-conditionally-load-sqlalchemy-model-relationships-in-fastapi.md b/_posts/2024-08-04-conditionally-load-sqlalchemy-model-relationships-in-fastapi.md index 5e2b1b9..1d2630f 100644 --- a/_posts/2024-08-04-conditionally-load-sqlalchemy-model-relationships-in-fastapi.md +++ b/_posts/2024-08-04-conditionally-load-sqlalchemy-model-relationships-in-fastapi.md @@ -254,12 +254,9 @@ class RelationshipLoader: [*exclude_classes, cls] # excluding the current class because we don't want bidirectional relationships to create infinite loop ) for nested_rel, nested_strategy in nested_relationships.items(): - # if it is a nested relationship, I am assuming it should be loaded with selectinload. - # i don't know a better way to handle this but this is working fine for us. - combined = load_strategy["selectinload"].copy() - combined.extend(nested_strategy["selectinload"]) - combined = {"selectinload": combined} - relationships[f"{rel.key}.{nested_rel}"] = combined + ((strategy_name, attr),) = load_strategy.items() + ((_, nested_attr),) = nested_strategy.items() + relationships[f"{rel.key}.{nested_rel}"] = {strategy_name: [*attr, *nested_attr]} return relationships