Reputation: 500
There are 2 nodes
They are connected with the relationship
(:Roadmap)<-[:IS_SHOWN_ON_ROADMAP]-(:Program)
Each time a program gets removed from the roadmap an endDate
property gets set on the relationship. If that same program gets added back to the same roadmap a new relationship gets added without and endDate
property. (this way we can go back in time and see the state of things in the past).
So there can potentially be any number of [:IS_SHOWN_ON_ROADMAP]
relationships between any two (:Program)
and (:Roadmap)
nodes. There for if there are n relationships, either n or n - 1 of them will have an end date. All will have an end date is the program is not currently on the roadmap, or one of them will not have an endDate if it is currently on the roadmap.
So my question: In cypher how can I ask the question "Show me all programs that are not currently active on the Roadmap?"
AKA, if there is at least one relationship with an endDate
that is null, then don't return it.
OR: only return programs where all relationships have an endDate
The query I have (that doesn't quite work) is
MATCH (rm:Roadmap)<-[r:IS_SHOWN_ON_ROADMAP]-(p:Program)
WHERE r.endDate IS NOT NULL
RETURN p
This query will still return a program that is active on the roadmap, if it was removed some time in the past.
Example: If there are two relationships, one with an endDate
(because it was removed) and one without an endDate
(because it is currently associated with the roadmap).
I need to figure out a way in cypher to loop over all relationships between each program and roadmap and not return that program if at least one of the relationships does not have an end date.
Upvotes: 2
Views: 472
Reputation: 16375
You can try using the ALL function:
MATCH (rm:Roadmap)<-[r:IS_SHOWN_ON_ROADMAP]-(p:Program)
WITH p, collect(r) as rs WHERE ALL(rel in rs WHERE rel.endDate IS NOT NULL)
RETURN p
Upvotes: 2