Skip to content

Commit

Permalink
update find to support nested fields (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
aMahanna authored Nov 28, 2024
1 parent cdf3576 commit 623c29b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion arango/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 623c29b

Please sign in to comment.