Exclude relational data

How does one “exclude” relational data. If I have objects with user relationships on them how do I say I only want to get down a subset of the data available on the user.

I am doing

dqb.setRelated(related: ["likes.nickname"])

And it isn’t working. I am getting all of the data down including e-mail etc.

Additionally is there a way to simple get a count of relationships back without actually getting any of the data?

Hi, Chris.
If you want to exclude/include some properties from the object itself (not it’s related objects), you should set the list of the properties with the method: setProperties

Yes, you can use Count API and pass where clause. For example, if you have table Posts and Likes, and relations one-to-many from Posts to Likes in column likes, then you make count on Likes table with following query:
Posts[likes].objectId = 'objectId of user post'.
Result will be a number of post’s likes.

Hope it helps.

Hello Chris,

You can use LoadRelationsQueryBuilder to get only necessary properties. E.g if your Users table has relation 1:N to the Likes table:

let queryBuilder = LoadRelationsQueryBuilder(relationName: "likes")
queryBuilder.setProperties(properties: ["nickname"])

let dataStore = Backendless.shared.data.ofTable("Users")
dataStore.loadRelations(objectId: "UserObjectId", queryBuilder: queryBuilder, responseHandler: { likes in
    for like in likes {
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")

Unfortunately there is a bug for the class approach, the internal ticket BKNDLSS-20066 created and it will be fixed as soon as possible.


1 Like

Hello Chris,

Issue with LoadRelationsQueryBilder class approach has been fix in version 5.6.5 of Swift-SDK.