Support Topics Documentation Slack YouTube Blog

Relations To Other Tables From Users Table Flutter SDK - Data Service

Ok, I fixed the first error so Ive removed that part. However this code still doesn’t work… and it should… It keeps saying it can’t find an object in the related table with a null ID. However the ID clearly isn’t null because my prints check it and I see the objects in the Database after creation. I have NOOO IDEA what’s going on.

static void _saveCar(Map car, GeoPoint location) async {
    /* HashMap<String, Object> childObject = new HashMap<String, Object>();
    childObject.put("objectId", "3464C734-F5B8-09F1-FFD3-18647D12E700");

    ArrayList<Map> children = new ArrayList<Map>();
    children.add(childObject); */

    await Backendless.data.of("Car").save(car).then((savedCar) async {
      await Backendless.geo.savePoint(location).then((savedLocation) async {
        var idLoc = savedLocation.objectId;

        Map mapLoc = savedLocation.toJson();

        String stringLoc = savedLocation.toString();

        print("This is savedLocation var: $idLoc");

        print("This is savedLocation map: $mapLoc");

        print("This is savedLocation String: $stringLoc");

        await Backendless.data
            .of("Car")
            .addRelation(savedCar, "location:Car:n", children: [idLoc]);
      });
    });
  }

Hi, Parki!

I can reproduce your problem on Android. Seems like a problem in Android SDK. Internal ticket BKNDLSS-19877 was created. We will let you know about its progress.

Regards,
Andrii.

@parki_catapulta, no, this is not a bug, the problem is in the code:

We’re working on the Flutter docs at the moment. Until then, you can use the Android docs since the APIs are almost identical:
https://backendless.com/docs/android/data_add_relation_with_objects_android.html

Thanks, Mark and Andrii. Passing the saved GeoPoint object “savedLocation” was what I first tried and it wasn’t working. It now recognizes the object but it says it “doesn’t exist in the related table”. Im confused because when I check the Geolocation Table in the Console, I see a row containing the id that appears in the “Not found” message.

Im assuming maybe the method trying to set the relation is being called before the savedLocation object has actually been registered in the DB so it doesn’t actually exist when the setRelation() method is called.

Copy-paste of Error
E/flutter (30263): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(1303, Unable to create relation. Child object with id ‘5F81B35E-F424-F57C-FFC7-5A89C2400E00’ is not found in the related table., Unable to create relation. Child object with id ‘5F81B35E-F424-F57C-FFC7-5A89C2400E00’ is not found in the related table.)

Copy-Paste of my Console Output of the Var, Map and String versions of savedLocation

I/flutter (30263): This is savedLocation Var: 5F81B35E-F424-F57C-FFC7-5A89C2400E00
I/flutter (30263): This is savedLocation Map: {objectId: 5F81B35E-F424-F57C-FFC7-5A89C2400E00, latitude: 32.800755, longitude: -96.81614, categories: [Default], metadata: {}}
I/flutter (30263): This is savedLocation String: GeoPoint{objectId=‘5F81B35E-F424-F57C-FFC7-5A89C2400E00’, latitute=32.800755, longitude=-96.81614, categories=[Default], metadata={}}

Registered Geopoint with ID '5F81B35E-F424-F57C-FFC7-5A89C2400E00’

Error Screenshot

Different Attempt - Same Error

Hello, Samuel.

I’ve checked your code and got correct behavior without any errors:

Check schema in your “Car” table, relation to GeoPoint have to be with correct type “Geo Point Relationship”, not “Data Object Relationship”.

And as advice. You’re mixing the async/await code with promises .then(). Your code will be easier to debug if you use or first approach, or second.

Regards,
Andrii.

@parki_catapulta @Samuel_Franco
We have released 0.4.0 version of plugin with correctly working method setRelation.

1 Like

Note: SHOULD I MAKE A NEW POST FOR THIS ERROR?

Thanks, Andri. I kept my code as it was, actualized the Backendless dependency and all CRUD is working fine for Android. IOS stopped working after I ran packages get.

Im using backendless_sdk: 0.4.0. inside dependencies: in pubspec.yaml

This is the IOS error:

Thanks for report.
I look into this code and see the next:

let enumValue = DataTypeEnum(rawValue: stringValue)
result[$0.key] = enumValue.index

And I check this enum’s init with rawValue:

public init(rawValue: RawValue) {
    switch rawValue {
    case "UNKNOWN": self = .UNKNOWN
    case "INT": self = .INT
    case "STRING": self = .STRING
    case "BOOLEAN": self = .BOOLEAN
    case "DATETIME": self = .DATETIME
    case "DOUBLE": self = .DOUBLE
    case "RELATION": self = .RELATION
    case "COLLECTION": self = .COLLECTION
    case "RELATION_LIST": self = .RELATION_LIST
    case "STRING_ID": self = .STRING_ID
    case "TEXT": self = .TEXT
    default: self = .UNKNOWN
    }
}

It’s not optional, because it has default .UNKNOWN value.
I’ve created new project with backendless_sdk and it is compiled with no errors.
Try to remove your Podfile in ios/ folder and let Flutter create new one.

Regards,
Andrii.