AntonTerekhov / OrientDB-PHP

Binary protocol for OrientDB for PHP applications (Beta)
http://code.google.com/p/orient/wiki/NetworkBinaryProtocol
BSD 3-Clause "New" or "Revised" License
108 stars 23 forks source link

recordUpdate with loaded OrientDBRecord object #10

Closed AVGP closed 12 years ago

AVGP commented 12 years ago

I stumbled upon an IMHO weird behaviour when trying to use a OrientDBRecord object with recordUpdate. For some reason, using an existing OrientDBRecord object loaded from the database updating this record and saving it to the database using recordUpdate did not behave like I would have expected. Here is a result:

$recordID = "5:1";
$record = $db->recordLoad($recordID);
$record->data->name = "Jane";
$db->recordUpdate($recordID, $record);

This will not update the name of the record with ID #5:1 to Jane. It will, anyway, increment the @version by one on the $record object to the same (incremented) value it returns - like it did update the record. However, if you do:

$db->recordUpdate($recordID, "name:'Jane'");

it will update the name property. This weird behaviour can currently circumvented like this:

$recordID = "5:1";
$record = $db->recordLoad($recordID);
$newRecord = new OrientDBRecord();
$newRecord->className = $record->className;
$newRecord->data = $record->data;
$newRecord->data->name = "Jane";
$db->recordUpdate($recordID, $newRecord);

which does update the record as intended.

Wouldn't the first way be easier and more obvious?

AntonTerekhov commented 12 years ago

Thanks for report.

However, I can't reproduce it. In example.php 87475cb its same mechanics:

  1. Create record
  2. Load it to new var $recordLoaded
  3. Change field on var $recordLoaded
  4. Update record with $recordLoaded
  5. Load record to $recordReLoaded
  6. Field has its new value.

What version of OrientDB, php and OrientDB-PHP you're using?

AVGP commented 12 years ago

I am running OrientDB 1.0rc9, PHP 5.4.0-2 (which might be a bit optimistic) and OrientDB-PHP in revision fe9029a917985572d1a93f7148e500231beda68f (Feb, 15th).

If I find the time later on, I'll try to reproduce the issue using the current git-snapshot of OrientDB-PHP with the original example.php and then test with my case again.

AntonTerekhov commented 12 years ago

Ok. You can also use latest tag 'beta-0.4.5(1.0rc9-snapshot_r4983)'

AntonTerekhov commented 12 years ago

Seems all fine.

AVGP commented 12 years ago

Yep, I can't reproduce it with the latest tag, too. All fine.