redislabs-redisgraph-php icon indicating copy to clipboard operation
redislabs-redisgraph-php copied to clipboard

Nodes insert error

Open miwe01 opened this issue 2 years ago • 2 comments

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);
    }

miwe01 avatar Jul 08 '22 08:07 miwe01