How to Save Objects With Relations and Create Dynamic Schema
I added the following method copied from the docs:
void _saveOrder() {
Map order = {
"orderNumber": 1,
"orderName": "Office Supplies",
};
Map orderItem1 = {
"name": "Printer",
"price": 99.0,
"quantity": 1,
};
Map orderItem2 = {
"name": "Paper",
"price": 19.0,
"quantity": 10,
};
Backendless.data.of("Order").save(order).then((savedOrder) {
print("Order has been saved");
Backendless.data.of("OrderItem").save(orderItem1).then((savedOrderItem1) {
print("First order item has been saved");
Backendless.data
.of("OrderItem")
.save(orderItem2)
.then((savedOrderItem2) {
print("Second order item has been saved");
Backendless.data.of("Order").addRelation(
savedOrder, "orderItems:OrderItem:n", children: [
savedOrderItem1,
savedOrderItem2
]).then((response) => print("Relation has been set"));
});
});
});
}
Backendless.data.of(“Order”).addRelation() has two compile time errors:
savedOrder.toString() fixes this one.
Map<dynamic, dynamic> savedOrder
The argument type ‘Map<dynamic, dynamic>’ can’t be assigned to the parameter type ‘String’.
Can’t do much about this one.
The named parameter ‘children’ isn’t defined.
Try correcting the name to an existing named parameter’s name, or defining a named parameter with the name ‘children’.
Future addRelation(
String parentObjectId,
String relationColumnName, {
List childrenObjectIds,
String whereClause,
}) // doesn’t use named parameters
I had a similar problem with Mission: API Services -CodelessShoppingCartService. I modified the downloaded code to fix the errors but it didn’t work.
I found a post that recommended:
- Upgrading to backendless_sdk: ^7.1.8
- Running flutter clean the flutter pub get
It worked.
I did the same for this code but it had no effect.
Thanks in advance
Chuck