Realtime Database - set properties not possible?

I’m using Realtime database to get notified everytime I update something from my database and everything works perfectly fine, which is great. However in my database I actually need a value which will give me the number of users located inside a related column. And that is possible by setting the properties like “Count(likes)”, but I’m not able to use setProperties when using Realtime database. Is there any workaround to achieve that and retrieve that value from relation column?

Hello @Stefan_Jovanovic

What if you will use the handleResponse?
From “updatedOrder” we can get an id of the updated object and use it in getObjectCount with “Person[city].objectId = updatedOrder.objectId” whereClause

My table schema:

Regards,
Viktor

1 Like

getObjectCount() does not accept where clause directly, but dataQueryBuilder instead.

@Stefan_Jovanovic

Here is an example

TABLE=ColorPalette
RELATIONAL_COLUMN=likes

Each row inside my table contains MORE then 0 Users inside my ‘likes’ relational column.
This is the exact where clause I used:
query.whereClause = “ColorPalette[likes].objectId = ‘037EF750-1AF7-4AC6-8CA1-47315B38D2D7’”

And still I’ve received 0 as a result of that getObjectCount() function. I’m really confused.
Btw, thank you for providing me all the information. :slight_smile:

@Stefan_Jovanovic

Sorry I did not write which table name must be used in getObjectCount

For your case, It seems to be:
TABLE NAME=Users
WhereClause=“ColorPalette[likes].objectId = ‘037EF750-1AF7-4AC6-8CA1-47315B38D2D7’”

That’s the exact thing I wrote, but I’m getting 0 as a response and not the exact number of objects. Here’s my code:


    override suspend fun getLikeCount(): Int? {
        return suspendCoroutine { continuation ->
            val query = DataQueryBuilder.create()
            query.whereClause =
                "ColorPalette[likes].objectId = '037EF750-1AF7-4AC6-8CA1-47315B38D2D7'"
            backendless.of(ColorPalette::class.java)
                .getObjectCount(query, object : AsyncCallback<Int> {
                    override fun handleResponse(response: Int?) {
                        Log.d("BackendlessDataSource", "$response")
                        continuation.resume(response)
                    }

                    override fun handleFault(fault: BackendlessFault?) {
                        Log.d("BackendlessDataSource", "${fault?.message}")
                        continuation.resume(-1)
                    }
                })
        }
    }

Hello @Stefan_Jovanovic

Could you try to test it with our REST Console, it might be an issue with Roles/Permissions

I did not change any permission, I’m using all default ones.
Btw is this the right GET request? Because here I’m still getting 0.

could you please show a request/response without the count property?

I get an empty list in that case?

as you can see the query is not correct or there is no data for the query, that’s why you get a zero for count

try this one

likes.objectId = '037EF750-1AF7-4AC6-8CA1-47315B38D2D7'

Do you want to load ColorPalette objects which contain a Like object with id 037EF750-1AF7-4AC6-8CA1-47315B38D2D7, is that correct?

1 Like

Okay I’ve found a way. Thank you for your help!

great, could you please share your solution it might be helpful for the community

I’ve used a different approach for calculating the total number of objects inside a relational column:

    override suspend fun getLikeCount(): List<ColorPalette> {
        val queryBuilder: DataQueryBuilder = DataQueryBuilder
            .create()
            .setProperties("Count(likes) as totalLikes")
            .setWhereClause("objectId = '037EF750-1AF7-4AC6-8CA1-47315B38D2D7'")

        return suspendCoroutine { continuation ->
            backendless.of(ColorPalette::class.java)
                .find(queryBuilder, object : AsyncCallback<List<ColorPalette>> {
                    override fun handleResponse(response: List<ColorPalette>) {
                        continuation.resume(response)
                    }

                    override fun handleFault(fault: BackendlessFault) {
                        continuation.resume(emptyList())
                    }
                })
        }
    }

I’ve also added a new field to my ColorPalette model class, called ‘totalLikes’, so that I can store the result inside it.

1 Like