Reputation: 858
I am fairly new to Neo4J, and have been trying to build a social network app using Cypher queries as annotated queries in Spring Neo4J.
How can I restrict the user node to have only one relationship with the address node using a cypher command/query or any configuration? Basically, I don't want the user to have multiple address relationships.
Upvotes: 3
Views: 798
Reputation: 41676
You can model your User entity like this:
@NodeEntity
public class User {
@GraphId Long id;
@Indexed String name;
@RelatedTo(type="ADDRESS")
Address address;
}
Then SDN will make sure that there is only one ADDRESS
relationship from an User
to an Address
.
Upvotes: 0
Reputation: 39915
You can do this using a TransactionEventHandler
. A TransactionEventHandler is a component written in Java and registered with your graphDatabaseService instance. In it's beforeCommit
you can veto the transaction.
Be warned, writing and using TransactionEventHandler is a advanced concept in Neo4j.
Upvotes: 0