1
我有以下的「用戶」類:只有單一的屬性可以被保存
<?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:[email protected]: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
創建其他屬性似乎被忽略。
我相信我缺少一些非常基本的東西;上述代碼有什麼問題?