Getting this error at custom event handler.
I want create user and make 1:1 relation to my table TokenStorage.
- I’ve create 1:1 mapping at TokenStorage table schema (key user to table User, 1:1)
- custom handler:
public function handleEvent( $runner_context, $event_args ) {
// add your code here
print("setting user ");
$user = new BackendlessUser();
$user->setEmail( "teest-user@test.com" );
$user->setPassword( "teest-user@test.com" );
$user = Backendless::$UserService->register($user);
// create a new TokenStorage object to store the user+VK association.
$ts = new TokenStorage();
$ts->setaccessToken("123");
$ts->setvkID("555");
$ts->setuser( $user );
// save object
$saved_obj = Backendless::$Data->of( 'TokenStorage' )->save( $ts );
}
- My TokenStorage data class
<?php
namespace com\backendless\letsride\events\custom_events;
use backendless\model\Data;
use backendless\model\BackendlessUser;
class TokenStorage /*extends Data*/ {
protected $accessToken;
protected $vkID;
protected $user;
public function __construct() {
//parent::__construct();
$this->user = new BackendlessUser();
}
public function setaccessToken($token = ""){
$this->accessToken = $token;
}
public function setvkID($id = 0){
$this->vkID = $id;
}
public function setuser($user) {
$this->user = $user;
}
}
- User created successfully. But got error
Missing ___class property for entity: data. Error code:1020
When creating record to TokenStorage with user relation.
Hi Denis,
Just to clarify the situation: you create a TokenStorage with a relation to BackendlessUser, try to save this TokenStorage object, and as a result 1) you receive an error about missing ___class property 2) BackendlessUser object is created 3) TokenStorage is not created
Is it right?
Could you please try to add __class property manually and check if it prevents the error?
The value of this property should be the same as the table name, in your case - TokenStorage. And verify that you have exactly three underscore (’’) symbols in the beginning of the property name - ___class.
I can’t call setProperty("___class", “tokenStorage”) coz Tokenstorage class didn’t inherit Data class.
Here is my current dump from RequestBuilder:
___class property is present in request.
RequestBuilder -> doRequestArray
(
[accessToken] => 123
[vkID] => 555
[user] => Array
(
[data] => Array
(
[email] => teest-user@ltest.com
[password] => teest-user@ltest.com
[fb_last_name] =>
[userStatus] => ENABLED
[uname] =>
[gender] =>
[created] => 1458136730000
[fb_first_name] =>
[facebookId] =>
[ownerId] =>
[ava] =>
[__meta] => {"relationRemovalIds":{},"selectedProperties":["fb_last_name","uname","gender","created","fb_first_name","facebookId","ownerId","ava","password","___saved","___class","name","updated","email","objectId"],"relatedObjects":{}}
[name] =>
[updated] =>
[objectId] => 8CD6C92C-F18C-7C8D-FF1E-DE7577F19600
)
[___class] => BackendlessUser
)
[___class] => TokenStorage
)
OK, thanks for clarification that ___class property does exist in the request.
Could I also ask you to prepare some minimal PHP code example and schema export with which we could reproduce your issue? It would greatly reduce the time we would spend on fixing it.
Send it to support@backendless.com
Thanks in advance!
Hi!
This issue fixed and new version available on github https://github.com/Backendless/PHP-SDK