Sorting a Repeating Group by linked Data Type's attribute

Hi gang. I’m not sure if this is a Database question or a front-end sorting/config question. Bear with me, thanks. :slight_smile:

I’m trying to sort a Repeating Group using a field (“Album Length”) that’s not actually part of my repeating group’s source data type (“Owned Album”). But it IS part of a linked thing. Is this possible without plugins?

A music collection example:
Let’s say I have a thing called Owned Album for each music CD that I own. The album has a length, say 60 minutes. If I have a bunch of users, it seems silly to store “60” on every user’s Owned Album. Everybody owns the same CD and it’s the same 60 minutes for everybody. There’s nothing special about my copy vs. your copy of the same CD - at least with respect to the album length. Because of this, I have another Data Type called Album Info which contains that universal album information, like Album Length.

Owned Album does contain a field called AlbumInfo which is of type Album Info. The question is: how do I sort my repeating group of Owned Albums by Length, when Length is a field belonging to Album Info? Do I really need to create a redundant field on Owned Album and store the length there too? Feels wrong to do so.

Hopefully that made sense. Thanks in advance!!!

Hi there, @ThatFizzGuy… to the best of my knowledge and as silly as it seems, I believe the only way to do the sort without a plugin is to have a redundant field. Sorry to be the bearer of less-than-ideal news, but this one just is what it is.

Best…
Mike

2 Likes

Blerg. OK, thanks @mikeloc !

1 Like

I love that the forum is showing me the translation icon for your post because of the word Blerg. Then, when I click the icon, is shows a 500 error. So, I guess blerg just means blerg. :slight_smile:

1 Like

Ha!

Blerg (excl.): a noise made in exasperation

1 Like

Yeah i think a redundant data field is probably the best solution.

But don’t view it as a defeat. Database design is a complex thing and our idea of a “clean” design often isnt how a database should be built.

Data redundancy can be a very good tool to avoid data “distance” (pretty sure that there is technical jargon for this). If data is hidden far away in parent datathings, and it needs to be retrieved/sorted by/filtered with etc, then having a redundant field where you need it is completely ok. This mainly applies to frontend stuff, especially if the data needs to be listed in a repeating group. You dont want your user to wait precious seconds for stuff to be retrieved just so that you can make your database ‘tidy’.

Im in no way a data scientist so if anybody wants to chime in and refute everything im all for it ahah
Happy bubbling

3 Likes

thanks @nico.dicagno

Definitely interested to hear if anyone out there has a magical workaround to my problem - ideally without relying on a plugin. In the meantime, a redundant field it is…

I believe you can do this using @keith 's List Shifter plug-in. Here’s a video someone made that demos how to do it (both ways - List Shifter and duplicated field).

The way Bubble handles it’s database operations is more like a No-SQL database such as Firebase rather than the Postgres database it’s using under the hood. For a while, as a SQL guy, this was a deal-breaker for me with Bubble because it’s putting limits on the control you have over the DB. Once I got over myself, it’s actually OK to deal with by using duplicated fields. My mantra is “optimise for reads over writes” in other words organise your database structure to make it very performant for retrieving data into lists and other areas of the UI which often means duplicated (or redundant) fields. Writes can be done in the backend so any extra processes are hidden from the user in terms of performance and you can use backend DB triggers to keep duplicated fields up-to-date with changes in the source data. @petter 's book on performance is a brilliant resource for organising performant data structures.

3 Likes

thanks @gazinhio . I actually watched that before posting. Helpful, though I’m hoping to avoid plugins and additional external dependencies wherever possible. Looks like a sweet plugin though!

UPDATE: missed your other text on my initial read. Thanks for the added info! Very helpful.

I consider Lift Shifter a sort of “must-have” for looping and such that I almost consider it part of Bubble now :slight_smile:

2 Likes

Another alternative way to do this without plugins is by having the “Album Length” have a field called “Owned Album”. Then you can search for the Album length and choose each items Owned Album and sort accordingly.

This is so true. Optimise for what you are doing 90% of the time (showing stuff in lists, mostly).

Database triggers are really helpful for de-normalising data (however much the SQL DBA in me bristles) into fields for sorting and privacy rules.

'Dont repeat yourself ’ - unless you have to.

1 Like