Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
633 stars 197 forks source link

Fixed invalid match when trying to attach to a node whose id is 0 #360

Open mrbig opened 2 years ago

mrbig commented 2 years ago

When trying to attach a node where the id is 0 the generated CypherQuery was missing the end node from the MATCH part.

This bug come out when neo started to reuse ids of deleted nodes: because the first id is 0, when this happened instead of connecting to the new node, a ton of edges were created between nodes with the same label.

This patch checks if the end node has an id, and won't ignore it from the query even if the value is the numeric 0.

For missing values (false, null, unset) the behavior was not changed.

I have also added a unit test to visualize the problem.