我有以下“用户”类:
<?php
use GraphAware\Neo4j\OGM\Annotations as OGM;
/**
* @OGM\Node(label="User")
*/
class User {
/**
* @OGM\GraphID
* @var int
*/
protected $id;
/**
* @OGM\Property(type="string")
* @var string
*/
protected $username;
/*
* @OGM\Property(type="string")
* @var string
*/
protected $password;
/*
* @param string $username
* @param string $password
*/
public function __construct($username, $password) {
$this->username = $username;
$this->password = $password;
}
/*
* @return string
*/
public function getUsername() {
return $this->username;
}
/*
* @return string
*/
public function getPassword() {
return $this->password;
}
/*
* @param string $password
*/
public function setPassword($password) {
$this->password = $password;
}
}
我正在尝试使用它,如图所示:
>>> require_once 'User.php'
=> 1
>>> use GraphAware\Neo4j\OGM\EntityManager;
=> null
>>> $manager = EntityManager::create('http://neo4j:superstrongpassword@localhost:7474');
=> GraphAware\Neo4j\OGM\EntityManager {#171
+"annotationDriver": GraphAware\Neo4j\OGM\Mapping\AnnotationDriver {#178},
}
>>> $x = new User('foo', 'bar');
=> User {#217}
>>> $manager->persist($x)
=> null
>>> $manager->flush()
=> null
但是,如果我在Neo4j“浏览器”中运行以下查询,我只能看到以下内容被创建:
$ match (x) return x
Rows
x: username: foo
似乎跳过了其他属性的创建。
我相信我错过了一些非常基本的东西;上面的代码有什么问题?
答案 0 :(得分:4)
密码@Property注释的docblock缺少*
:
/*
* @OGM\Property(type="string")
* @var string
*/
protected $password;
第一行:/*
应该有两颗星/**
/**
* @OGM\Property(type="string")
* @var string
*/