Backendless Support
 

Registering/Updating a user with related data object(s)

When a user object is registered (or updated), it may be necessary to create a relation between the user and some other entity/object stored in Backendless. 

Since a user object is structurally a collection of properties, it is very easy to relate an object stored in Backendless with a user. 

The code below shows how to register a user with a related object referenced through the "address" property.

                                          For Objective-C and Swift implementations CLICK HERE

Asynchronous sample (Android and Plain Java):
BackendlessUser user = new BackendlessUser();
user.setEmail( "spiderman@backendless.com" );
user.setPassword( "greeng0blin" );
Address address = new Address();
address.setStreet( "123 Main St" );
address.setCity( "Dallas" );
address.setState( "Texas" );
address.setZip( "75032" );
user.setProperty( "address", address );
Backendless.UserService.register( user, new AsyncCallback<BackendlessUser>()
{
 @Override
 public void handleResponse( BackendlessUser backendlessUser )
 {
 System.out.println( "[ASYNC] user has been registered" );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "server reported an error - " + backendlessFault.getMessage() );
 }
} );
Synchronous sample (Plain Java only):
BackendlessUser user = new BackendlessUser();
user.setEmail( "spiderman@backendless.com" );
user.setPassword( "greeng0blin" );
Address address = new Address();
address.setStreet( "123 Main St" );
address.setCity( "Dallas" );
address.setState( "Texas" );
address.setZip( "75032" );
user.setProperty( "address", address );
Backendless.UserService.register( user );
System.out.println( "[SYNC] user has been registered" );

Once a developer runs the code above, the Users table shows the registered user and a link to the related Address object: 

Is article helpful?