Backendless Support
 

Client class to data table mapping

 Data tables created in Backendless and the client-side classes a developer writes or obtains through Backendless code generation, have a direct correlation. By default a table and the corresponding client-side class have the same name. This is true for all Backendless SDKs which support object-oriented data access. This includes Android, Java, Objective-C, Swift, JavaScript, ActionScript and .NET. 

For example, consider the following data table: 

The table has two relation columns: "locations" and "owner". The former references a collection of objects (one-to-many relation) from the Location table: 

The "owner" column from the Restaurant table references an object from the built-in Users table. Also notice the Location table has a relation column for the Menu table.

The classes representing these tables would look as shown below:

Restaurant class (the code below is a Java code and is a "compressed" version of the class. One can also sees the full source code listing in the github repository of the Restaurant-To-Go project):

                                       For Objective - C and Swift implementations CLICK HERE

package com.backendless.samples.restaurant.entities;
import com.backendless.Backendless;
import com.backendless.BackendlessCollection;
import com.backendless.BackendlessUser;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.persistence.BackendlessDataQuery;
import java.io.Serializable;
public class Restaurant implements Serializable
{
 private String name;
 private String ownerId;
 private String objectId;
 private String cuisine;
 private java.util.Date updated;
 private java.util.Date created;
 private java.util.List<Location> locations;
 private BackendlessUser owner;
 // skipping getters and setters for brevity
}

Notice the class contains a Java property for every single column in the data table. This also applies to the relations, such as the "locations" and the "owner" fields.

The Location class is defined as (see the full source code listing on Github):

                                                        For Objective - C and Swift implementations CLICK HERE

JAVA

package com.backendless.samples.restaurant.entities;
import com.backendless.Backendless;
import com.backendless.BackendlessCollection;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.persistence.BackendlessDataQuery;
import java.io.Serializable;
public class Location implements Serializable
{
 private String streetAddress;
 private String country;
 private String objectId;
 private java.util.Date updated;
 private java.util.Date created;
 private String ownerId;
 private String city;
 private String phoneNumber;
 private Menu menu;
 // skipping getters and setters for brevity
}

The mapping between the table definition and the source code can be done by hand or automatically using Backendless source code generator. When written by hand, it is very important to observe the naming conversion for the table and column names.

Review related topic:

Is article helpful?