Struggling with Single Step Retrieval Flutter

Hello, I am using custom classes in Flutter and want to retrieve linked data but haven’t been able to do so despite spending hours trying to figure out the docs. I have two tables, Exhibit and Venue. I have set a 1:1 relation from the exhibit to a venue in the console and it works just fine (have attached an image of that).

However I don’t understand how to access the linked data. I want to be able to do exhibit.linked_venue.address to get the address of the linked_venue if that’s possible, but honestly have no idea how to do that. Any help would be greatly appreciated!

I have the following function in my Exhibit class to get the first item in the db. Can you help me adapt it so the instance also contains the information from the linked_venue column?

static Future<Exhibit?> firstExhibit() async {
    var dbdata = await Backendless.data
        .withClass<Exhibit>()
        .findFirst()
        .then((firstOne) {
      return firstOne;
    });
    return dbdata;
  }

Hello, you can set relations in findFirst’s parameter relations, like this:
await Backendless.data.withClass<Exhibit>().findFirst(relations: ['linked_venue']);

Best Regards, Nikita.

After updating the class constructor to add linkedVenue, my code now looks like this:

However when I do firstOne!.linkedVenue it keeps returning null. I tried to make the relation in the findFirst function be ['linked_venue.venue'] as per your comment above but that doesn’t work either. I’m not sure what I’ve done wrong?

Hello, @Ilayda_B.

Also, you need to create the Venum class, and Object? linkedVanue field in your class should be Venue? linked_venue.

Best Regards, Nikita.

Hello @Nikita_Fedorishchev,

I’ve made the change you suggested but am still getting null returned when I do firstOne.linkedVenue. I’ve attached a screenshot of both the Exhibit and Venue Class so you can see what’s in there. Am I missing anything from the Venue class?

On the plus side, I am able to access the Venue properties using .linkedVenue…well they’re showing up but they are always null since linkedVenue is always null, but this is definitely a step in the right direction!

Screenshot 2023-02-01 at 16.51.02

It’s because name of field in your code and in database is different. You need to change name of column in db to linkedVenue or change field in code to linked_venue

Regards, Nikita.

1 Like

Thank you for your reply, I changed the name in my db to linkedVenue and now I am able to access the information I need!