0

I'm using the Neo4jphp REST API and I'm having a problem of relating a node iv created in my code to a node im retrieving from the neo4j database. I'm retrieving the node as follows

$querystring="MATCH(n)"."WHERE has (n.name) and n.name='Interests'"."RETURN n"; $query=new Everyman\Neo4j\Cypher\Query($client,$querystring); $result=$query->getResultSet();

im creating another node in my code using createNode() $friend=$client->makeNode()->setProperty('name',$fname)->save(); I used relateTo() to relate them

$m=$client->getNode($result);
$m->relateTo($friend,$movi)->save();//$movi is a common movie name

but getting this error

PHP Catchable fatal error:  Object of class Everyman\\Neo4j\\Query\\ResultSet could not be converted to string in /var/www/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Cache/EntityCache.php 

would really appreciate any input

4

2 回答 2

2

neo4jphp 查询返回一个行对象(即使只有一个响应)所以

$m=$client->getNode($result);

行不通

试试这个

$querystring="MATCH(n) WHERE has (n.name) and n.name='Interests' RETURN n";
$query=new Everyman\Neo4j\Cypher\Query($client,$querystring);
$result=$query->getResultSet();
foreach($result as $resultItem)
{
   $resultArray[] = $resultItem['x'];
   //$resultItem['x'] is the node object, now $result array is an array of node objects
}
$friend= $client->makeNode()->setProperty('name',$fname)->save();
$resultArray[0]->relateTo($friend,$movi)->save();

此代码也适用于此查询(更易于阅读)

$querystring="MATCH (n {name:"Interests"}) RETURN n";
于 2014-05-19T00:12:36.570 回答
0

我会这样做:

$queryString = "MATCH(n) WHERE has (n.name) and n.name= {name} RETURN ID(n)";
$query = new Everyman\Neo4j\Cypher\Query($client,$queryString,array('name'=>'Interests'));

$result = $query->getResultSet();

$resultArray=array();
foreach($result as $row)
{
    array_push($resultArray,$row['n']);
}

$friend = $client->getNode($resultArray[0]);
$friend->relateTo($friend,$movi)-save();
于 2015-04-12T12:56:50.083 回答