Skip to content

Class to Table Mapping

When you use custom classes in your application for data persistence, Backendless maps the database table names to the names of the classes. For example, the following code is automatically mapped to the Person table:

@interface Person : NSObject

@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSNumber *age;

@objcMembers class Person: NSObject {
    var name: String?
    var age: NSNumber?

The Person table in the Backendless database:


When the name of the class is different than the name of the corresponding table in the database, it is necessary to customize the mapping. This can be achieved with the following API:

[[ of:[YOUR-CLASS class]] mapToTableWithTableName:@"TABLE-NAME"]; "TABLE-NAME")


Argument                Description
"TABLE-NAME"  name of the table to map to a class.
YOUR-CLASS reference to a class to map to the table.

The API is not necessary if the class name is the same as the table name. The only exception to this rule is when your application retrieves related objects using the "Custom Class" approach. In this case, if application should establish mappings between client-side classes and the related (children) tables. For example, consider the following schema:

Order (parent) table:


OrderItem (child) table:


If any related OrderItem objects are retrieved along the parent Order object (via auto-load or single-step relation retrieval), then the application must establish a mapping for the OrderItem table before the data is retrieved.

[[ of:[OrderItem class]] mapToTableWithTableName:@"OrderItem"]; "OrderItem")