Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-30-2020 03:28 PM
I want to implement a soft delete - deleted_at flag is null by default and set to the date when node is deleted.
I would like to add check for deleted_at is not null in all queries.
Is there any way to add such checks or modify the query before it is actually executed?
09-08-2020 01:55 PM
Negation in a graph database is tricky and expensive. Every query would have to load ALL relevant nodes to check each for a null value, before excluding those you wish to ignore.
All of the following are functionally equivalent to deleting a property:
null
: a.date = null
REMOVE a.date
All of the following are functionally equivalent to checking that a property is not set:
null
: WHERE a.date = null
WHERE NOT EXISTS(a.date)
is null
: WHERE a.date IS NULL
That shows that what you're asking for is possible, but not a good thing to plan to build. If your data had a million nodes, with all but one set with a deleted_at
date, every query would have to load all one million nodes, check that the date was set to remove the node from the running list, to return the single node you cared about.
Add two properties:
is_active
booldeleted_at
dateTimeAlways set the is_active
when you create your nodes. Set it to false
, and the deleted_at
date when you delete. Then the million-node example isn't a problem.
09-08-2020 02:17 PM
Thank you for taking the time to provide your thoughts.
Looks like I should be able to use the Filter parameter in loadAll query.
09-08-2020 03:40 PM
Be able to? yes Should? no
All the sessions of the conference are now available online