PHP neo4j OGM - Recursion detected -


i'm using entitymanager in project. can successfuly read/add entites , relations between them db have 1 problem.

i have 2 nodes employee , document , relationship between them employee has document.

php class emloyee:

<?php namespace app\models;  use graphaware\neo4j\ogm\annotations ogm; use \graphaware\neo4j\ogm\common\collection;  /**  *  * @ogm\node(label="employee")  */ class employee implements \jsonserializable {      public function __construct() {         $this->documents = new collection();         $this->addresses = new collection();     }      /**      * id      * @var int      * @ogm\graphid()      */     protected $id;      /**      * name      * @var string      *       * @ogm\property(type="string")      */     protected $name;      /**      * lastname      * @var string      *       * @ogm\property(type="string")      */     protected $lastname;      /**      * personalidnumber      * @var string      *       * @ogm\property(type="string")      */     protected $personalidnumber;          /**      * @var document[]|collection      *       * @ogm\relationship(type="has", direction="outgoing", collection=true, mappedby="employees", targetentity="document")      */         protected $documents;       /**      * @var address[]|collection      *       * @ogm\relationship(type="has", direction="outgoing", collection=true, mappedby="employees", targetentity="address")      */         protected $addresses;      public function getaddresses() {         return $this->addresses;     }      public function getdocuments(){         return $this->documents;     }          public function getname(){         return $this->name;     }      public function setname($name){         $this->name = $name;     }      function getlastname() {         return $this->lastname;     }     public function setlastname($lastname){         $this->lastname = $lastname;     }      function getpersonalidnumber() {         return $this->lastname;     }     public function setpersonalidnumber($personalidnumber){         $this->personalidnumber = $personalidnumber;     }        public function jsonserialize() {         return [             'id' => $this->id,             'name' => $this->name,             'lastname' => $this->lastname,             'personalidnumber' => $this->personalidnumber,              'addresses' =>$this->addresses->toarray(),             'documents' =>$this->documents->toarray()         ];     } } 

php class document:

    <?php  namespace app\models;  use graphaware\neo4j\ogm\annotations ogm; use graphaware\neo4j\ogm\common\collection;  /**  *  * @ogm\node(label="document")  */ class document implements \jsonserializable{      public function __construct() {         $this->employees = new collection();          $timezone = new \datetimezone('europe/ljubljana');         $t = microtime(true);         $micro = sprintf("%06d",($t - floor($t)) * 1000000);         $dt = new \datetime( date('y-m-d h:i:s.'.$micro, $t));         $dt->settimezone($timezone);         $this->crdate = $dt->format('ymdhis.u');         $this->validfrom = $this->crdate;     }      /**      * @ogm\graphid()      *      * @var int      */     protected $id;      /**      * @var string      *       * @ogm\property(type="string")      */     protected $name;      /**      * @var string      *       * @ogm\property(type="string")      */     protected $uniquename;      /**      * @var string      *       * @ogm\property(type="string")      */     protected $path;       /**      * @var string      *       * @ogm\property(type="string")      */     protected $ext;      /**      * @var string      *       * @ogm\property(type="string")      */     protected $documentid;      /**      * @var string      *       * @ogm\property(type="string")      */     protected $validfrom;      /**      * @var string      *       * @ogm\property(type="string")      */     protected $validto;      /**      * @var string      *       * @ogm\property(type="string")      */     protected $crdate;      /**      * @var string      *       * @ogm\property(type="string")      */     protected $language;           /**      * @var string      *       * @ogm\property(type="string")      */     protected $type;          /**      * @var string      *       * @ogm\property(type="string")      */     protected $description;          /**      * @var docemployees[]|collection      *       * @ogm\relationship(type="has", direction="incoming", collection=true, mappedby="documents", targetentity="employee")      */        protected $employees;       public function getemployees() {         return $this->employees;     }      public function getid() {         return $this->id;     }      public function getname() {         return $this->name;     }     public function setname($name) {         $this->name = $name;     }      public function getuniquename() {         return $this->uniquename;     }     public function setuniquename($uniquename) {         $this->uniquename = $uniquename;     }      public function getpath() {         return $this->path;     }     public function setpath($path) {         $this->path = $path;     }      public function getext() {         return $this->ext;     }     public function setext($ext) {         $this->ext = $ext;     }      public function getdocumentid() {         return $this->documentid;     }     public function setdocumentid($documentid) {         $this->documentid = $documentid;     }          public function getvalidfrom() {         return $this->validfrom;     }      public function setvalidfrom($validfrom) {         $this->validfrom = $validfrom;     }      public function getvalidto() {         return $this->validto;     }      public function setvalidto($validto) {         $this->validto = $validto;     }          public function getlanguage() {         return $this->language;     }        public function setlanguage($language) {         $this->language = $language;     }      public function getcrdate() {         return $this->crdate;     }        public function setcrdate($crdate) {         $this->crdate = $crdate;     }      public function gettype() {         return $this->type;     }        public function settype($type) {         $this->type = $type;     }      public function getdescription() {         return $this->description;     }        public function setdescription($description) {         $this->description = $description;     }      public function getfullname(){         return $this->path.$this->uniquename;     }      public function jsonserialize() {         return [             'id' => $this->id,             'name' => $this->name,             'uniquename' => $this->uniquename,             'path' => $this->path,             'ext' => $this->ext,             'validfrom' => $this->validfrom,             'validto' => $this->validto,             'language' => $this->language,             'crdate' => $this->crdate,             'type' => $this->type,             'description' => $this->description,             'employees' => $this->employees->toarray()         ];     } } 

then have 2 api endpoints use slim framework rest api have 2 methods return data.

for employees:

    public function getallemployees(){     $this->logger->info(__class__.':'.__function__);       $employeesrepository = $this->dbentity->getrepository(employee::class);     $employees = $employeesrepository->findall();      return $employees; } 

for documents:

    public function getalldocuments(){     $this->logger->info(__class__.':'.__method__);      $documentrepository = $this->dbentity->getrepository(document::class);     $documents = $documentrepository->findall();      return $documents; } 

so problem when uncomment line

            'employees' => $this->employees->toarray() 

in document class

i runtime error recursion detected

without line works fine.

can me missing?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -