redislabs-redisgraph-php
redislabs-redisgraph-php copied to clipboard
Nodes insert error
When you add just nodes in the graph and no edges, you get an error in the function getCommitQuery().
One solution to fix the issue.
public function getCommitQuery(): QueryInterface
{
$query = 'CREATE ';
foreach ($this->nodes as $index => $node) {
$query .= $node->toString(); // split the $query in $query->toSring() and ', '
if ($index < count($this->nodes) - 1) { // added this line
$query .= ',';
}
}
$edgeCount = count($this->edges);
if(!empty($edgeCount)){ // check or you get an error
if(count($this->nodes) != 0)
$query .= ', '; // added this line
foreach ($this->edges as $index => $edge) {
$query .= $edge->toString();
if ($index < $edgeCount - 1) {
$query .= ',';
}
}
}
return new Query($this->name, $query);
}