Ostico / PhpOrient

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

Automatically created default fields not returned after record creation #39

Closed andreyvk closed 8 years ago

andreyvk commented 9 years ago

Hi @Ostico,

I'd like to ask if it's possible to return fields which were created by default in a call to recordCreate. For instance, if I have a Test class:

create class Test abstract extends V
create property Test.id string
alter property Test.id default uuid()

Then the following will print null to the console:

. . .
$rec = ( new Record() )->setOData( [] )->setRid( new ID( 9) ); 
$record = $this->client->recordCreate( $rec );
print_r($record["id"]);

Does latest OrientDB protocol support avoiding this sort of behavior?

Ostico commented 8 years ago

Hi @andreyvk ,

are you sure that the cluster ID of your class Test is 9?

From my tests, you created a class Test abstract extends V, but an abstract class has no ID.

So, there is no record inside this class because it is not concrete.

You writed in the V class ( ID = 9 ) i think, so the records are in #9:0 but they have not default values.

andreyvk commented 8 years ago

Hi @Ostico,

It's not about abstract class really. I think I've made a mistake there with the test data. So the Test class isnt abstract of course:

create class Test extends V
create property Test.id string
alter property Test.id default uuid()

Try that with (my Test class cluster id is now 100):

$client = new PhpOrient( 'localhost', 2424 );
$client->username = 'user';
$client->password = 'pass';
$client->connect();
$client->dbOpen( 'test', 'user', 'pass' );

$rec = ( new Record() )->setOData( [] )->setRid( new ID( 100 ) );
$record = $client->recordCreate( $rec );

print_r($record["id"]);

and you will get:

PHP Fatal error:  Uncaught exception 'OutOfBoundsException' with message 'The searched key id does not exists in this record: PhpOrient\Protocols\Binary\Data\Record::__set_state(array(
   'rid' =>
  PhpOrient\Protocols\Binary\Data\ID::__set_state(array(
     'cluster' => '100',
     'position' => '1',
  )),
   'oClass' => NULL,
   'version' => 1,
   'oData' =>
  array (
  ),
))' in /home/ubuntu/shared/www/nsure/lib/vendor/ostico/phporient/src/PhpOrient/Protocols/Binary/Data/Record.php:196
Stack trace:
#0 /home/ubuntu/shared/www/nsure/scripts/tests/temp/create_record.php(37): PhpOrient\Protocols\Binary\Data\Record->offsetGet('id')
#1 /home/ubuntu/shared/www/nsure/scripts/tests/temp/create_record.php(41): nsure\scripts\seeds\temp\CreateRecordTest->run()
#2 {main}
  thrown in /home/ubuntu/shared/www/nsure/lib/vendor/ostico/phporient/src/PhpOrient/Protocols/Binary/Data/Record.php on line 196

That might be binary protocol limitation of course. I'd just like to know if it is or not. If it is, then I will file an issue to OrientDB. Thanks

Ostico commented 8 years ago

Hi @andreyvk

if the behaviour is that you described, i think this is be a driver Issue because of:

https://github.com/Ostico/PhpOrient/blob/master/src/PhpOrient/Protocols/Binary/Operations/RecordCreate.php#L107

The recordCreate method only update the content of the RID and Version as OrientDB provide them for the client.

I've to study about this: https://github.com/Ostico/PhpOrient/blob/master/src/PhpOrient/Protocols/Binary/Operations/RecordCreate.php#L111

If the new record content is not in the 'changes' => $changes key/value pair, a new query to the database must be issued.

Reopen and investigating again.

andreyvk commented 8 years ago

Thanks!

Ostico commented 8 years ago

Hi @andreyvk , i found that $changes does not transport the new uuid for the just created record.

I will make a query to get the content.

Ostico commented 8 years ago

Fixed

andreyvk commented 8 years ago

@Ostico, I see. Hope that at some point Orient guys can add this feature to the binary protocol. And thanks!