Exception retrieving data from Table with 1:1 relation to Users

Hi!

I had a Tours table working ok in my Flutter App…

Now, I have added a 1:1 relation (guide) to Users table in the Tours table.

I have added the new property in the Tours Custom Class:

@reflector
class Tour {
// … Other properties
BackendlessUser guide;

}

And when I retrieved the data adding the guide property to related:

final queryBuilder = DataQueryBuilder();
queryBuilder.related = [‘images’, ‘guide’];
Backendless.data.withClass().find(queryBuilder).then((foundObjects) {
// handle response
}.catchError((error) {
print(“Server reported an error: $error”);
});

I get this exception:

I’m missing something or maybe a bug in Flutter SDK?

Thanks in advance.
Dani
APP ID: EF16A871-80DD-437B-FF13-FAF3968E1D00

Hi @Dani_Sevilla

Did you follow the instructions in this article?

Also make sure to call initializeReflectable() inside your main method and run the following command:
flutter packages pub run build_runner build

Best Regards,
Maksym

Hi @Maksym_Khobotin

Yes, I followed this instructions and before adding the new relation property all is working ok.

After I have added the new property (with the relation) and I have done the “flutter packages pub run build_runner build” I get an exception in the find method.

Regards,
Dani

Can you please provide the full code sample to reproduce the issue, @Dani_Sevilla?
Please include your custom class and the code to find the object.

Ok @Maksym_Khobotin I will try to generate a new Test Flutter project with the error and I will send you…

Thank you!

@Maksym_Khobotin In this link you can find a Flutter test project with the exception:

I think there is a bug in Flutter SDK.

Regards,
Dani

@Maksym_Khobotin I have continued with the tests and the problem is the relationship with the Users table.

If I do exactly the same but the relationship is against another custom table everything works fine.

I hope this helps you find the problem.

Regards,
Dani

Thank you for the test project. I will check out and let you know once I figure out the problem.

Best Regards,
Maksym

Hi @Dani_Sevilla

I checked your test project and it’s worked fine for me.
I made only two changes: added io.socket dependency to app/build.gradle to enable RT for my android emulator and printed out the results:

Backendless.data.withClass<Tour>().find(queryBuilder).then((foundObjects) {
      print("Found: $foundObjects");
      foundObjects.forEach((f) => print(f.guide));
      // handle response
      allTours = foundObjects;
      notifyListeners();
    }).catchError((error) {
      print("Server reported an error: $error");
    });

And I got the following result in my console:

I/flutter ( 5927): Found: [Instance of 'Tour', Instance of 'Tour']

I/flutter ( 5927): BackendlessUser{{userStatus: ENABLED, lastLogin: null, ___class: Users, updated: null, name: User Test, email: test@mail.com, ownerId: 149245CF-4E3F-58D8-FF16-A6703553ED00, socialAccount: BACKENDLESS, created: 2020-02-10 17:37:21.729, blUserLocale: en, objectId: 149245CF-4E3F-58D8-FF16-A6703553ED00}}

I/flutter ( 5927): BackendlessUser{{userStatus: ENABLED, lastLogin: null, ___class: Users, updated: null, name: User Test, email: test@mail.com, ownerId: 149245CF-4E3F-58D8-FF16-A6703553ED00, socialAccount: BACKENDLESS, created: 2020-02-10 17:37:21.729, blUserLocale: en, objectId: 149245CF-4E3F-58D8-FF16-A6703553ED00}}

There were no problems or exceptions.

Make sure you use backendless_sdk version 1.1.0 or higher. There was an issue with BackendlessUser class in earlier versions.

Also you can specify which device do you use for debugging the app. Android emulator with API 24 works fine in my case.

Best Regards,
Maksym

Hi @Maksym_Khobotin

Yes, I’m using backendless_sdk version 1.1.0 as you can see in pubspec.yaml

I’m testing in iPhone 11 Pro Simulator from MacBook Pro

Okay, thank you for this useful information. I will try to run the project on iPhone Simulator and let you know the results.

@Maksym_Khobotin I have checked the test project in a Android Simulator and all is working fine for me too.

The same project in IOS is crashing with exception. It’s clear that the problem is in the IOS part of the Flutter SDK.

Yes, I can reproduce the issue on iPhone Simulator too. I’ve created the internal ticket BKNDLSS-20581. We will keep you updated.
And thanks you a lot for pointing out the issue!

Best Regards,
Maksym

Ok, @Maksym_Khobotin thank you for your assistance.

Any news about when the next version of the Flutter SDK will be ready with this problem fixed?

Hi @Dani_Sevilla

This issue has been fixed. Please check out the new Flutter SDK version 1.1.2!

Best Regards,
Maksym

Hi @Maksym_Khobotin

Sorry but I have updated the project to Flutter SDK version 1.1.2 and the problem persists in iOS. Now you don’t get an exception but the relation is always null.

Here you have a test project with de SDK updated and the problem.

To test this issue in database_service.dart comment line 34 and uncomment line 38:

Regards,
Dani

Hi @Dani_Sevilla, again :slight_smile:

The issue with Users table relation in iOS is currently fixed.
To update your local cached version of Swift SDK please run

cd ios
pod update

in your Flutter project and run it again.

Best Regards,
Maksym

Hi @Maksym_Khobotin!

Yes! I have done the “pod update” and now it works!

Good Job.

Thanks!