Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-24-2019 02:37 PM
I really just want a 'hello world' example for how to make something work. I want to create a trigger on a relationship when new property is assigned to it that matches a specified key.
So this is a bit contrived, but let's say that whenever a property is added to a label with the property key of 'firstname', our trigger adds another property, lasname: 'Smith'.
I have tried some variations on this, but even when Neo4j accepts the trigger, it doesn't actually invoke the trigger's action. Here's what I have tried last:
CALL apoc.trigger.add('testRelProp','UNWIND apoc.trigger.propertiesByKey({assignedRelationshipProperties},'firstname') as prop
WITH prop.relationship as r
SET r.lastname = "Smith"',
{phase:'before'});
I have to admit that I am guessing on prop.relationship because I haven't seen it defined anywhere for relationships.
I would be happy to see this run, or any example of the relationship-property-trigger.
05-24-2019 08:46 PM
Can't comment on using apoc.trigger
. I don't think the writers of that project recommend it for mission-critical work. However, if you need a bulletproof solution, you can either:
A) Implement a plugin, aka "unmanaged extension". This is a JVM solution you can deploy in the /plugins
folder to implement serious app work on the database machine, in the native/fast Neo4j verbatim. If you go this deep, you can also register a "transaction hook" whereby you can be guaranteed to make your changes in response to other changes.
B) Run a scheduled task executing Cypher against the DB, using your own infrastructure
outside of Neo4j.
05-26-2019 10:29 AM
The ideal scenario would be to work with continually improving community solutions (APOC).
At the moment, the documentation seems to be my issue. I find no example anywhere of a relationship firing a trigger upon property assignment to that relationship.
I’ll keep in mind the option of building my own unmanaged extension for these. I have coded in java in the past, but to be completely honest I would trust the community code over my own for something that runs inside Neo4j. If you’re offering to write a custom trigger, I can keep that in mind too, as my needs evolve.
05-31-2019 10:58 PM
You're right, ideally APOC can do everything you need, and that's true especially if you only work with a single instance via the native browser. My comments are definitely biased toward my use of it for a backing store for an API truth state, where we may want to run scheduled tasks anyway, and we already support a plugin.
APOC can get you 98% of the way there – maybe others can chime in?
All the sessions of the conference are now available online