My use case is that I’m trying to surface the ‘most liked’ comment card that has been added to a board by users.
The ‘Card’ is a thing, and it has a list field which contains all of the users who have liked it.
The way I have it configured just now is that I do a search for the type of card, add a constraint to filter it to the relevant board, then I’m trying to use the ‘change which field…’ option in order to get to the point where I have the results coming back in descending order based on the count of Likes. In my head, that should mean that if I then select the :first item option when I try to render the result somewhere, it would would equate to the item with the ‘max’ number of likes.
There’s obviously something wrong with my understanding there though, as that doesn’t work
Firstly, I’m not sure I understand you current database set up… going from your screenshots, it looks as though you have a field on the Stop Card datatype for Stop Card Board which is a ‘text’, and you’re matching the Slug of the current Page’s Board?
Which I guess is ok (it will work), but seems a bit of a long-winded way to set a Board field on the Stop card datatype… why not just set a Stop Card Board field on the Stop card? is there a specific reason you’re using a text field?..
In any case, to address your main question… the simplest (and most performant way) by far to achieve this will be to add a number field on the Stop Card datatype which is a count of the likes.
Otherwise you’ll have to do some advanced filtering which will not only be more complicated to set up, but will be a lot slower to load, especially once you have a lot of data…
By the way, the ‘Change which field’ for sorting is a way to dynamically set which field is used for sorting, so has nothing to do with what you’re trying to achieve here.
So my advice would be to add a like count field to the Stop Card datatype to keep things simple and fast.
Ha, I definitely don’t understand my current database setup either
I’m very much just crashing about in here, and am certainly making a bunch of mistakes - a good example is what you’ve called out - I’m conscious that lookups based on text are non-performant, but I’ve not gotten to grips with how to set proper system IDs for the things I create in bubble yet, so I’m kind of just using the slug as a unique identifier in the ‘filter to the correct board’ scenario.
As you say, ‘it works’ for now , but (if my app turns out to be any good) I’m sure there will come a time when I will need to refactor how I’m doing this. It defo feels super clunky - I’m sure I’m missing something fundamental about how to reference/join different database entities in bubble.
On the upside, I’ve implemented the Like Counter field as you’ve suggested, and have set it to increment/decrement with each new ‘like’/‘unlike’ - I can now sort by that field and select the first item, so all is now working as hoped - thanks!
I’m wondering if I can apply any of this learning to my next challenge, which is feeding a chart element with counts of some other elements which exist in a list on my Stop Card Feels slightly more complex, but I’ll give it a shot myself, and will post a new thread if I get horrifically stuck
The good thing about the Bubble database is that you don’t need to do that at all - it does it for you…
Just create a field on a datatype that has the ‘type’ of another datatype, then you can easily link datatypes (things) without needing to reference unique IDs or slugs or anything else.
I’m wondering if I can apply any of this learning to my next challenge, which is feeding a chart element with counts of some other elements which exist in a list on my Stop Card Feels slightly more complex, but I’ll give it a shot myself, and will post a new thread if I get horrifically stuck
Without knowing the specifics of what you’re trying to do I can’t give specific guidance there, but from what you’ve described it sounds like it should be fairly straight forward…
So give it a try, and if you get stuck I’m sure someone in here will be able to help you out…