Neo4j naming conventions for similar actions in Cypher

I know that there is no restriction on naming relationships, although it is difficult to get one guide and work with it on all the relationships that we may encounter.

You would go with something like this:

(u:User)-[:LIKES]->(p:Post)
(u:User)-[:LIKES]->(c:Comment)

and then a label-based query; Or something like this:

(u:User)-[:LIKES_POST]->(p:Post)
(u:User)-[:LIKES_COMMENT]->(c:Comment)

Another case is a streaming chat application in which it Usercan start a stream with several other users, here is the structure I have in mind:

# the thread
CREATE (ct:ChatThread {created_at: timestamp()})

# the thread starter
(u:User {user: 1})<-[:IN_THREAD {type: 'owner'}]-(ct)

# members of the thread
(u:User {user: 2})<-[:IN_THREAD {type: 'member'}]-(ct)
(u:User {user: 3})<-[:IN_THREAD {type: 'member'}]-(ct)
+4
source share
1 answer

I will consider the first example you cited:

(u:User)-[:LIKES]->(p:Post)
(u:User)-[:LIKES]->(c:Comment)

against

(u:User)-[:LIKES_POST]->(p:Post)
(u:User)-[:LIKES_COMMENT]->(c:Comment)

, , , ( 4 - ). :

  • , , , Post Comment, LIKES .
  • Posts LIKES, , LIKES_POST, . LIKES, . ... , , ( , ).
  • , , .
+4

Source: https://habr.com/ru/post/1538836/


All Articles