Sorting data by backend IDs

I can successfully pull data from a table in Backendless, no problem. But since it’s general “post” data (content created by logged-in users), how can I sort it in Appgyver to only show, say, posts by a specific user instead of all users when they’re logged into their profile?

Another way to phrase it: I’d like to sort the posts by a data column in Backendless called ownerId. If the ownerId of the user matches that stored in post’s equivalent column, show that user’s content to them – but not to other users.

I’ve tried playing around with the Where clause in the Data tab, response paths, just about every option it offers, but nothing works so far.

Much obliged,
Dom

Hi, you can use the SELECT_BY_KEY formula function (docs) to select posts by a certain user.

Get posts by owner 112233:

SELECT_BY_KEY(data.AllPosts, "ownerId", 112233)

Nice! Thank you, Mari. This works perfectly, as it stands.

Quick question: I just want to confirm that this is actually secure on the frontend, considering that we’re pulling the entire post table and then filtering what the logged-in user can see to posts which match their ownerId. Someone can’t just go into Inspect in Chrome and somehow expose all of the data, essentially, seeing other users’ content if it’s private, no?

Hi! You’re right, the SELECT method works only in case everyone’s posts are public, but a user can also see a list of their own posts.

If you want the posts to be private per each user, you should implement the backend so that each user can only get their own posts, i.e. configure the Backendless endpoint in a way that when you send a request with the user’s ID or session token, Backendless will only return the records owned by that user.

1 Like

Ah, thanks for confirming that, Mari. :slight_smile: So SELECT would be better suited for a search bar-type function where an input is bound to, say, a page variable and that variable is plugged into the Value for the formula, which then filters a list of public users, for example? Fair enough. I’ll have use for that, too.

While I’ll be asking in the Backendless forums, perhaps, I can set up the API GET call (Appgyver-side) to only pull in posts which match the ownerId. If I understand Where clauses correctly, that’s where that might come in – I think…

In which case, back to square one!

Yeah exactly! By searching on the forums I was able to find this thread where someone has implemented that kind of where clause in Composer :slight_smile:

1 Like

Thanks for this, Mari. I was also drawing from a forum thread which seems to mention the same use case (Appgyver-to-Backendless), but after four hours, still no luck. Will look into it more over the weekend.

1 Like