You want to use Neo4j "Labels". Try this:
$userLabel = Neo4jClient::client()->makeLabel('User');
$user->node->addLabels(array($userLabel));
More information here: https://github.com/jadell/neo4jphp/wiki/Labels
Вопрос
In my domain model I have an entity called User
, and I am creating a new node
of that type in this manner:
public static function register(User $user){
if(!$user->node)
$user->node = new Node(Neo4jClient::client());
try {
$user->node->setProperty('__type__', TYPE_USER);
$user->node->setProperty('username', $user->getUsername());
$user->node->setProperty('password', $user->getPassword());
$user->node->setProperty('name', $user->getName());
$user->node->setProperty('age', $user->getAge());
$user->node->setProperty('location', $user->getLocation());
$user->node->setProperty('website', $user->getWebsite());
$user->node->setProperty('about', $user->getAbout());
$user->node->setProperty('rating', $user->getRating());
$user->node->save();
$user->setId($user->node->getId());
$userIndex = new Index(Neo4jClient::client(), Index::TypeNode, TYPE_USER);
$userIndex->add($user->node, 'username', $user->username);
return true;
} catch (Exception $e){
return false;
}
}
And, the node gets created in the database and everything is fine. Except...this way, the node is created as 'default node', as if I was using cypher CREATE n
, for example.
What I actually want is to create a node of specific type, as CREATE (n:User)
but without having to actually use cypher directly.
Any idea how can achive this?
Решение
You want to use Neo4j "Labels". Try this:
$userLabel = Neo4jClient::client()->makeLabel('User');
$user->node->addLabels(array($userLabel));
More information here: https://github.com/jadell/neo4jphp/wiki/Labels