Struggling to return all items in table that satisfy linked condition

Hello,

I have yet another Flutter question! This time I am struggling with where clauses on a relation column :frowning:

I have a Category table (see below):

I also have an Exhibit table that contains a 1:N relation column with the Category table called linkedCategories (see below):

Is there a way to retrieve every sculpture exhibition from the Exhibits table? I.e. where the linkedCategories column contains the objectId for the sculpture category?

Currently I have tried the following:

  static Future<List<Exhibit?>?> fetchExhibitWithCategoryId(
      Category category) async {
    var query = DataQueryBuilder()..related = ['linkedCategories'];
    String whereClause =
        "Exhibit[linkedCategories].objectId = '${category.objectId}'";
    DataQueryBuilder queryBuilder = query..whereClause = whereClause;
    var dbdata = Backendless.data
        .withClass<Exhibit>()
        .find(queryBuilder)
        .then((exhibits) {
      logger.d(exhibits); // returns []
      return exhibits;
    });
    return dbdata;
  }

All 3 exhibits in the Exhibit table contain the sculpture category. What am I doing wrong?

Hello, @Ilayda_B.

If I correctly understood you and you want to retrieve objects where related object contain “Sculpture” name you need to do this:

var query = DataQueryBuilder()
  ..loadRelations = ['linkedCategories']
  ..whereClause = 'linkedCategories.name=\'Sculpture\'';

var result = await Backendless.data.withClass<Person>().find(queryBuilder: query);

print(result);
return result;

Best Regards, Nikita.

Hi Nikita,

Thank you, as always, for your speedy response. I really appreciate your help!

Unfortunately ..loadRelations returns the following error:

The setter 'loadRelations' isn't defined for the type 'DataQueryBuilder'.
Try importing the library that defines 'loadRelations', correcting the name to the name of an existing setter, or defining a setter or field named 'loadRelations'.

When I click into data_query_builder.dart() to see what functions are available I can see class LoadRelationsQueryBuilder but don’t know how to use it…

Sorry, my mistake, it called ‘related’.

1 Like

Thank you SO much! This has made me so happy! It finally works as I need :pray:t4:

1 Like