cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Creation of relationship between existing nodes not reflected

saadiiii
Node

Greetings!

I am working on creating a relationship between 2 existing node programmatically using Python. While the nodes have been created, the query of creating the relationship is getting executed as code, but I am not able to visually see the relationship between the 2 nodes - such a relationship isn't even recognized in the Neo4j Browser.

 
def create_edge(tx, crimeID, junctID, dist) : 
query = 'MATCH (c:Crime), (j:Junction) WHERE c.crime_id = $crime_id AND j.id = $junction_id CREATE (c)-[r:NEAREST_CRIME_JN {distance: $distance, crime_id: $crime_id, junction_id: $junction_id}]->(j) return type(r)'
result = tx.run(query,crime_id=crimeID, junction_id=junctID, distance=dist)
return result

#takes in a transaction and the custom dictionary - containing the distance, crime_id and junction_id - connection to be made
def add_nearjn_edge(tx,nearjndict) : 
create_edge(tx,nearjndict["crime_id"],nearjndict["junction_id"],nearjndict["distance"])
print("Edge created")
 
"Edge created" is displayed for all records (about 11,986 records) - but the connection (directed arrow) is missing in the browser. The datatypes of the crime_id and junction_id are integer and string respectively, does that make a difference? Any leads to this as soon as possible will be much appreciated!!
1 ACCEPTED SOLUTION

Hi @saadiiii 

If the argument crime_id is passed as a String, a toInteger() statement is required.

From $crime_id to toInteger($crime_id)

query = 'MATCH (c:Crime), (j:Junction) WHERE c.crime_id = toInteger($crime_id) AND j.id = $junction_id CREATE (c)-[r:NEAREST_CRIME_JN {distance: $distance, crime_id: $crime_id, junction_id: $junction_id}]->(j) return type(r)'

https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-tointeger
 

View solution in original post

2 REPLIES 2

Hi @saadiiii 

If the argument crime_id is passed as a String, a toInteger() statement is required.

From $crime_id to toInteger($crime_id)

query = 'MATCH (c:Crime), (j:Junction) WHERE c.crime_id = toInteger($crime_id) AND j.id = $junction_id CREATE (c)-[r:NEAREST_CRIME_JN {distance: $distance, crime_id: $crime_id, junction_id: $junction_id}]->(j) return type(r)'

https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-tointeger
 

Thank you so much @koji !! This did the trick 🙂