Ostico / PhpOrient

PhpOrient - Official Php driver based on the binary protocol of OrientDB.
Other
68 stars 37 forks source link

How to obtain the LINKed records in a single query ? #64

Open fsieduc opened 8 years ago

fsieduc commented 8 years ago

context : create two records, the second has a LINK property named "friend" pointing to the first record

question : how to fetch both records, in one query, only knowing the second record's RID ?

   <?php
   use PhpOrient\PhpOrient;
   use PhpOrient\Protocols\Binary\Data\Record;
   $client = new PhpOrient('localhost', 2424);
   $client->dbOpen('test', 'root', 'root'); // a Graph database
   $me = $client->recordCreate(Record::fromConfig(['oClass' => 'V', 'oData' => ['label' => 'me']]));
   $you = $client->recordCreate(Record::fromConfig(['oClass' => 'V', 'oData' => ['label' => 'you', 'friend' => ''.$me->getRid()]]));
   <?php
   // and later, only knowing the $youRecordRid
   $records = $client->query("??? {$youRecordRid} ???"); // or any thing else but in one query
   assert(count($records) == 2);