Skip to content

Column Name Mapping

When your application uses custom classes to represent data objects stored in the database, Backendless maps the column names in the database to the fields/properties declared in a custom class. For example, consider the following class:

@interface Person : NSObject

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

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

When an instance of the class is saved in the Backendless database, it creates a table with the following schema:
person-table

As you can see the names of the columns match the names of the properties in the class. However, sometimes that mapping cannot be observed and a property in the class must have a different name or capitalization than the name of the column. In order to override the default mapping, Backendless supports an a special method which allows to map a property to a column. Consider the following example:

[[Backendless.shared.data of:[Person class]] mapColumnWithColumnName:@"Name" toProperty:@"name"];
[[Backendless.shared.data of:[Person class]] mapColumnWithColumnName:@"Age" toProperty:@"age"];
Backendless.shared.data.of(Person.self).mapColumn(columnName: "Name", toProperty: "name")
Backendless.shared.data.of(Person.self).mapColumn(columnName: "Age", toProperty: "age")

The example demonstrates the mapping of the "Name" and "Age" properties in the client application to the "name" and "age" columns in the database for the class Person. The mapping is bidirectional, it means it works for both saving objects in and retrieving from the database.

Important

Creating mappings for system level columns such as objectId, created, updated and ownerId is not supported.