You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I filter on the properties of a node class related to the target node class, I'd expect that if any of the related nodes match those filters, then it would return the target node.
E.g. I'm looking for dog owners who both own a dog that's >=10 years old AND own a dog that's a Terrier. They don't need to own a Terrier >= 10 years old, they could own two dogs that together meet the criteria.
If there is an alternative syntax (I tried various combinations of subquery, traverse_relations, and filters with Q's), then I'm also happy to use that.
Actual Behavior (Mandatory)
The neomodel filters give me "dog owners who own a dog that is >= 10 years old and is a Terrier", i.e. it enforces that a single node of the related class must meet all the filter conditions.
But I want it to additionally return Alice, who owns a Terrier and owns a dog >= 10 years old, as specified by the filter.
To get what I expect, I would need to run:
results = neomodel.db.cypher_query("""
MATCH (h:Human)-[:OWNS]->(d1:Dog)
WHERE d1.age >= 10
MATCH (h)-[:OWNS]->(d2:Dog)
WHERE d2.breed = "Terrier"
RETURN DISTINCT h
""", resolve_objects=True)[0]
print(results)
(but in order to support more complicated examples, I want to use neomodel's NodeSet functionality rather than custom cypher)
Specifications (Mandatory)
Currently used versions
Versions
OS: MacOS
Library: neomodel 5.4.1
Neo4j: 5.27.0
The text was updated successfully, but these errors were encountered:
One thing that surprisingly works is to add a second relationship on Human owns_dog2 = RelationshipTo(Dog, 'OWNS', model=StructuredRel), then make the filter:
This returns both Alice and Bob, as I wanted the original query to.
This is definitely a hack though, it's not feasible to add extra relationships up to the total number of filters I might want to apply on a relationship.
Hello, I understand your problem, and I see why you thought filter() would work the way you thought, I admit this can lead to confusion.
But it is how I think it is intended : combining two filters inside a single filter() creates an AND, and your case is more subtle than this.
Adding a second relationship definition will make neomodel consider it's two different paths so that makes sense that it works. It DOES feel a bit hacky ; but at the same time, models are not only designed for write operations, but also retrieval, so maybe that can work for you - look at how GraphQL makes some "virtual" properties that are actually traversals.
In any case, I can only think of that option and the custom Cypher option to do what you are trying to do.
Expected Behavior (Mandatory)
When I filter on the properties of a node class related to the target node class, I'd expect that if any of the related nodes match those filters, then it would return the target node.
E.g. I'm looking for dog owners who both own a dog that's >=10 years old AND own a dog that's a Terrier. They don't need to own a Terrier >= 10 years old, they could own two dogs that together meet the criteria.
If there is an alternative syntax (I tried various combinations of subquery, traverse_relations, and filters with Q's), then I'm also happy to use that.
Actual Behavior (Mandatory)
The neomodel filters give me "dog owners who own a dog that is >= 10 years old and is a Terrier", i.e. it enforces that a single node of the related class must meet all the filter conditions.
How to Reproduce the Problem
Run the script below.
Simple Example
It prints:
But I want it to additionally return Alice, who owns a Terrier and owns a dog >= 10 years old, as specified by the filter.
To get what I expect, I would need to run:
(but in order to support more complicated examples, I want to use neomodel's NodeSet functionality rather than custom cypher)
Specifications (Mandatory)
Currently used versions
Versions
The text was updated successfully, but these errors were encountered: