Hi. I have the following structure:
NodeA has relationships to multiple NodeB; the relationships have a property called 'preferred', which takes boolean values. I need to be able to atomically change the preferred NodeB. I am doing this with Cypher on version 1.8.
What I have now is two queries which look like this:
// reset the currently preferred, if any
start me = node({me}) match me-[r:LIKES]->t set r.preferred = false where r.preferred = true // this might result in no relationships changed, that's Ok - no preference yet
// set the new preferred
start me = node({me}), t = node({t}) match me-[r:LIKES]->t set r.preferred = true
(Parameters 'me' and 't' are Nodes that I already have and don't have to look up.)
This will be done in a single transaction so that it is atomic. However, I have a couple of questions:
1. Is it possible to do such a thing in a single query? Is this practical? Is it better to issue 2 simpler queries than 1 complex?
2. I would like to learn if the second query actually changed any relationship. This is for error checking - node 't' in the second query might not be related to 'me' at all, in which case the query would change 0 relationships. I think the easiest way for me would be to check the count of changed relationships if I could return that, and if it is 0, node 't' was unrelated to 'me'. How can I express this in Cypher?
Regards,
wujek