Hi,
I was trying to save some data to my tables using Custom Event in the server code. When I did
Backendless::$Persistence->save( $DataObj );
I received a weird exception: Backendless API return error: Missing ___class property for entity: data. Error code:1020
After tracing the issues, I realized that RequestBuilder.php is sending a request with this body:
{"data":{"phone_number":"81111111","data":189010},"___class":"TestData"}
So, I tested this body with a separate REST request, and true enough I got this error as well from my rest console. Right now, I can temporarily fix this issue by doing this:
RequestBuilder::doRequest( 'data', $data_array['table'], $data_array['data']['data']
in Persistence.php. However, I do not know the repercussion of this change and hope that the development team can fix this issue for the long term.
Alexander,
Could you please make sure you’re using the latest version of the SDK for PHP?
Regards,
Mark
That was the SDK which comes with the latest CodeRunner from the github.
Thanks. How long ago did you download it?
Around 4-5 days ago. I have checked the github on a daily basis for updates. The issue apparently still exists in the current code from github.
Hi Alexander!
Could you try to add ___class property in related json object? This is correct request body:
{"data":{"___class":"Data", "phone_number":"81111111", "data":189010},"___class":"TestData"}
Regards,
Kate.
That works, as in there was no more error, but it did not work the way I have expected. That JSON body added a new table “Data” to my database which is wrong. What I need was to save the data into the “TestData” table, hence the temporary fix which I made to Persistence.php. That fix actually saves the data correctly to their respective table. I was hoping if the dev team can come out with a permanent fix as I am unsure if this fix of mine will break other things.
Could you please show the class that the $DataObj variable contains instance of?
Also, there are a few changes in the SDK we made today. Could you please update the SDK and try again?
When I traced the code, the issue occurred at Persistence.php line 58:
return BackendlessCollection::prepareSingleItem( RequestBuilder::doRequest( 'data', $data_array['table'], $data_array['data'] ), $data_array["type"] );
In my original post, I did a printout of $data_array[‘data’] which is
{"data":{"phone_number":"81111111","data":189010},"___class":"TestData"}
$data_array was the object returned at line 45:
$data_array = $this->convertDataToArray( $data );
I believed that convertDataToArray function did what it was written to do.
Anyway, to help you further, here are the implementation of the class for my $DataObj:
<?php
namespace com\backendless\dver\events\custom_events;
use backendless\Backendless;
use backendless\model\Data;
class TestData extends Data {
public function __construct()
{
}
}
?>
Here’s the part where I instantiate and place the data:
$DataObj->setProperty("phone_number", "8111111");
$DataObj->setProperty("data", "189010");
Backendless::$Persistence->save( $DataObj );
By the way, the latest SDK did not fix the issue.