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:
import 'package:backendless_sdk/backendless_sdk.dart';
@reflector
class Person {
String name;
int age;
String objectId;
}
}
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:
Backendless.data.mapTableToClass(String tableName, Type type)
where:
Argument | Description |
---|---|
tableName |
name of the table to map to a class. |
type |
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.
Backendless.data.mapTableToClass( "OrderItem", OrderItem )