Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 122: Client class to data table mapping
May 11, 2015 by markpiller
Spread the love

It may already be obvious if you had followed this blog series. Data tables created in Backendless and the client-side classes you write or obtain 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:
restaurant table schema1 - Feature 122: Client class to data table mapping

The table has two relation columns: “locations” and “owner”. The former references a collection of objects (one-to-many relation) from the Location table:
location table schema1 - Feature 122: Client class to data table mapping

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 “compressed” version of the class. You can see full source code listing in the github repository of the Restaurant-To-Go project):

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):

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.

Share this post
Tweet about this on TwitterShare on FacebookGoogle+