Closed waza-ari closed 1 month ago
In _nest_join_data
I use join.join_prefix
as the key for the data, so it doesn't work if it's not passed. It could be just changed to the model's name or the join_prefix as well and it will fix this issue if join_prefix is None
.
def _nest_join_data(
data: dict[str, Any], join_definitions: list[JoinConfig]
) -> dict[str, Any]:
nested_data: dict = {}
for key, value in data.items():
nested = False
for join in join_definitions:
if join.join_prefix and key.startswith(join.join_prefix):
nested_key = join.join_prefix.rstrip("_") # here defining nested_key
nested_field = key[len(join.join_prefix) :]
if nested_key not in nested_data:
nested_data[nested_key] = {}
nested_data[nested_key][nested_field] = value # and using nested_key as the key
nested = True
break
if not nested:
nested_data[key] = value
return nested_data
Describe the bug or question Attributes from a joined model are not nested if no
join_prefix
is setTo Reproduce
Consider two simple models,
Hero
andAbility
Then, this code does not work as expected:
Returns this (unrelated columns are removed):
When adding a prefix, it (kinda) works:
Result is looking better