From 623c29bed9868ad4437745214cac4489b84f8814 Mon Sep 17 00:00:00 2001 From: Anthony Mahanna <43019056+aMahanna@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:45:26 -0500 Subject: [PATCH] update `find` to support nested fields (#354) --- arango/utils.py | 6 +++++- tests/test_document.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arango/utils.py b/arango/utils.py index 359b1e37..541f9d0c 100644 --- a/arango/utils.py +++ b/arango/utils.py @@ -120,5 +120,9 @@ def build_filter_conditions(filters: Json) -> str: if not filters: return "" - conditions = [f"doc.`{k}` == {json.dumps(v)}" for k, v in filters.items()] + conditions = [] + for k, v in filters.items(): + field = k if "." in k else f"`{k}`" + conditions.append(f"doc.{field} == {json.dumps(v)}") + return "FILTER " + " AND ".join(conditions) diff --git a/tests/test_document.py b/tests/test_document.py index 805486fe..37599507 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -1241,6 +1241,10 @@ def test_document_find(col, bad_col, docs): col.insert({"foo bar": "baz"}) assert len(list(col.find({"foo bar": "baz"}))) == 1 + # Test find by nested attribute + col.insert({"foo": {"bar": "baz"}}) + assert len(list(col.find({"foo.bar": "baz"}))) == 1 + def test_document_find_near(col, bad_col, docs): col.import_bulk(docs)