Skip to content

Commit 34b7547

Browse files
committed
🎨 [#143] added better many detection for nested fields
1 parent 567d019 commit 34b7547

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/openklant/components/klantinteracties/api/tests/test_expand.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_list_single_expansion(self):
5555
klantcontact["hadBetrokkenen"][0]["uuid"], str(self.betrokkene.uuid)
5656
)
5757
self.assertTrue(klantcontact["_expand"])
58-
expand = klantcontact["_expand"]["hadBetrokkenen"]
58+
expand = klantcontact["_expand"]["hadBetrokkenen"][0]
5959

6060
self.assertEqual(
6161
expand["bezoekadres"],
@@ -107,7 +107,7 @@ def test_list_multiple_level_expansion(self):
107107
klantcontact["hadBetrokkenen"][0]["uuid"], str(self.betrokkene.uuid)
108108
)
109109
self.assertTrue(klantcontact["_expand"])
110-
expand = klantcontact["_expand"]["hadBetrokkenen"]
110+
expand = klantcontact["_expand"]["hadBetrokkenen"][0]
111111

112112
self.assertEqual(
113113
expand["bezoekadres"],
@@ -193,7 +193,7 @@ def test_detail_single_expansion(self):
193193

194194
self.assertEqual(data["hadBetrokkenen"][0]["uuid"], str(self.betrokkene.uuid))
195195
self.assertTrue(data["_expand"])
196-
expand = data["_expand"]["hadBetrokkenen"]
196+
expand = data["_expand"]["hadBetrokkenen"][0]
197197

198198
self.assertEqual(
199199
expand["bezoekadres"],
@@ -244,7 +244,7 @@ def test_detail_multiple_level_expansion(self):
244244

245245
self.assertEqual(data["hadBetrokkenen"][0]["uuid"], str(self.betrokkene.uuid))
246246
self.assertTrue(data["_expand"])
247-
expand = data["_expand"]["hadBetrokkenen"]
247+
expand = data["_expand"]["hadBetrokkenen"][0]
248248

249249
self.assertEqual(
250250
expand["bezoekadres"],

src/openklant/components/utils/expansion.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ def _field_inclusions(
237237
if isinstance(inclusion_serializer, str):
238238
inclusion_serializer = import_string(inclusion_serializer)
239239

240-
many = True if hasattr(field, "child_relation") else False
240+
many = (
241+
True if hasattr(field, "child_relation") else getattr(field, "many", False)
242+
)
241243

242244
for obj in self._some_related_field_inclusions(
243245
new_path, field, instance, inclusion_serializer

0 commit comments

Comments
 (0)