As you probably know, Neo4j only supports directed relationship. The idea is to make you think about what the direction means for your domain. While at creation time you have to specify a direction, you're free to ignore direction at query time - you don't have to create a second relationship going backwards just for queries (or speed). This is what you most often do. However, in some cases, when you really want to make the point that a relation is unidirectional in termns of the domain, you'd create a second relationship with the inverse direction. At first, this felt like a workaround to me, but now I really like that I'm somewhat forced to thing about what the direction means for the domain. For a practical example, you might look at the second picture at this[1] (okay, my) graph gist. At the bottom right, there are the two modes that "Spring Data Neo4j" supports, which are both an alternative to each other. Here it makes sense to have two relationships back and forth, as they're an alternative to each other in terms of the domain and also allow me to do a directed query like "Show me the alternatives to X", where each mode shall list the other as an alternative.
Hope that helps, I wasn't sure whether you're asking for a best practice way to insert relationships using Python or generally more in the sense of domain modelling. I've obvisouly picked the second interpretation to answer to and it probably won't hurt to consider those aspects in any case :-) [1] http://gist.neo4j.org/?github-jotomo/neo4j-gist-challenge//learning-graph/learning-graph.adoc On 12/24/2013 05:02 PM, Abhishek Gupta wrote: > What is the best way to create undirectional relationships in neo4j? I > am using neo4j, py2neo. Here is how I insert the nodes and the > relationships: > > | > index_name =db.get_or_create_index(neo4j.Node,"index_name") > > defcreate_node(name): > returnindex_name.get_or_create("name",name,{"name":name}) > > definsert_triplet(triplet): > firstNode =create_node(triplet[0]) > secondNode =create_node(triplet[2]) > chain =neo4j.Path(firstNode,triplet[1],secondNode) > path =chain.get_or_create(db) > | > > Thanks in advance for replying. > > Regards > Abhishek > > -- > You received this message because you are subscribed to the Google > Groups "Neo4j" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
