Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-18-2020 08:05 AM
Hello, I'm using apoc 3.5.0.9 to implement triggers on my database, and I can't seem to find a way to have a trigger that blocks an update.
For instance, I have 10+ triggers that execute in "phase: after" once a certain property X is updated, and I wanted to have one other different trigger in "phase: before" that once said property X is to be updated, verified if it was a valid update based on a certain condition, and if not, it would be aborted and all the other 10+ triggers would not be activated.
What I'm trying to do is something similar to what is depicted below:
CALL apoc.trigger.add('blockUpdate','UNWIND apoc.trigger.propertiesByKey({assignedNodeProperties},"_executed") as prop
WITH prop.node as n
MATCH (n)<-[:someRelation]-(x)
WHERE x._included=true OR x._executed=0
--> ABORT AND CANCEL THE UPDATE ON NODE "n"
',
{phase:'before'});
Is this possible?
Solved! Go to Solution.
03-19-2020 01:11 PM
you can use call apoc.util.validate(<predicate>, <message>)
, seehttps://neo4j.com/docs/labs/apoc/4.0/misc/utility-functions/
03-19-2020 01:11 PM
you can use call apoc.util.validate(<predicate>, <message>)
, seehttps://neo4j.com/docs/labs/apoc/4.0/misc/utility-functions/
03-20-2020 07:21 AM
Hi @stefan.armbruster, and thanks for the quick reply.
I've tried to use that function but I can't seem to get it right. I have noticed that it requires 3 arguments, the third one being a vector of arguments, and as such, I've used an empty one. This is what I have:
CALL apoc.trigger.add('blockUpdate','UNWIND apoc.trigger.propertiesByKey($assignedNodeProperties,"_executed") as prop
WITH prop.node as n
CALL apoc.util.validate( EXISTS((n)<-[:CONDITION]-(x{_included:true, _executed:0})), "Error msg", [])',
{phase:'before'});
But after this trigger is inserted into the database, I can't do anything else... Can't create nodes, delete or update them. This is the error message I get after trying to do any of these operations:
Am I missing something concerning the syntax of this function?
Thanks again for your time.
EDIT (FIXED): If you just run that trigger neo4j will accept it, but if you have something in a query other than the CALL function you need to return something, and there is no error message concerning that. Instead, neo4j just crashes every other action, which is a rather odd behavior. To fix it, I just returned something after the CALL (it doesn't matter what is going to be returned). Just leaving this here in case it helps someone.
Once more, thank you.
All the sessions of the conference are now available online