Nested Collections and Records

I feel like there should be a simple answer to this but I can’t seem to find this addressed on any thread.

I’m trying to construct a series of nested collections and records. The app I’m building carries a lot of info on musical artists and what I’m trying to figure out is the following:

  • List of Artists (Collection)
    • Artist Detail (Record)
      • List of Albums from this Artist (Collection)
        • Album Detail (Record)
          • List of songs on the Album (Collection)

Just not sure the best way to structure this from a data perspective. Suggestions?

Your structure looks fine to me. What is your trouble?

I´m still learning about FB queries and filters, but was wondering if a flatter structure of say Artist then song, with album etc as a field under each song would make for easier searching and filtering later on?

1 Like

I too was worried that this kind of layout would not be optimal concerning data traffic and everything but it seems firebase actually advises it instead of using arrays. That makes sense for firebase to advise, though, as it increases the number of reads and writes – that they charge for…

Would like to hear from more experience back-end pros.

@stayfoolish , yeah I guess I should have been more clear. Even if I go this route I actually don’t know how to configure this in Appgyver.

I have 3 Data Resources set up that align with the main tables in Airtable: Artists, Albums, and Tracks.So far it’s been pretty straight forward to configure that data to display album and track lists overall but I’m struggling with how to configure a Get Collection to pull Albums from a specific Artist.

I set up a Get Record process that passes the Artist ID to an overview page that successfully shows various detail related to that artist record. I have created another “sub page” or tab that is supposed to reveal the artist’s albums but I don’t know how to do that. The Albums of course are tied to the respective artists in Airtable but how do you make that connection in Appgyver?

Sorry if this seems super basic. I feel like it should be obvious.

@Phil_Evans I am intrigued by this suggestion but don’t really understand it. Would you be willing to elaborate a bit and explain how you would configure this in Appgyver?

Just an idea (I dont know if i understood the question right): what if you use a group by.
So you have one table, all the artists in one column and all the albums in one column. In airtable you can group them by whichever column you like in 2 or 3 clicks. In appgyver you can group them with formulas.

Thanks, @Edvin_Rushitaj. This idea looks promising, but after fiddling with the GROUP function for a bit I’m not sure it will give me what I’m after (though it’s possible I’m misunderstanding). Let’s see if I can illustrate.

I have an artist dashboard page (see image) that is pulling from the Artist table in my Airtable using “GET COLLECTION”. Tapping here navigates to an “Artist Overview” page.

The Artist Overview page defaults to a Dashboard view that is pulling all the Artist details using a “GET RECORD” request and a page parameter with the Artist ID.

From here I want to tab over to the “Albums” area to view the Artist Albums. I assumed (based on my limited knowledge so far) that I would have to revert back to a GET COLLECTION request here to access a list of records (albums) but I don’t know how to make it dynamically pull the albums associated with the current artist ID.

Does that make sense? Please assume very limited experience here as I am very novice and trying to learn as I go.

Thank you all again for your help!

If you open a new page from a page which has the selected artist, you could configure the new page to receive a “page parameter” that you could set to the selected artist ID. Thus you can have that value on the next page as well.
Read here for more:

I was talking about the dB structure. But considering the appgyver side, everything just becomes a list of songs. Use a criteria to limit it to a specific album. Producing an album list might be harder, I don´t know if there is a “select unique” function.

Just throwing ideas out there really.

What are you actually trying to build? A personal music player or a some unique spin on the current ones?

Thank you @Mihaly_Toth . I used this process to open the “Artist Overview” page. So I created the page parameter and have no problem passing the Artist ID when using a “single data record” data variable.

This allows me to access all the “Fields” associated with that artist record. The problem is the Albums are not contained in an artist field but are records themselves that are linked to a specific Artist.

So to get a list of Albums I assume I have to use the “collection of data records” variable type which does not allow you to link to any particular ID or page parameter as far as I can tell (see below)

Am I making sense? It seems the idea of “nested lists” within specific records would be a pretty simple function but perhaps I am not describing it well.

How do you “link” the albums to the artist?
I mean in the database what is the reference?
Do the albums have a field named: “artist”: artistID?
Or do you have a list of albumIDs among the artist fields?

When using the get record collection you do have filtering options in the bottom right side of your screen.
If you have a field in the albums as artistId that would be the most straightforward way, because:
In that case you could do the following:
Get record collection from the resource ‘albums’. Filter condition would be set to:

artistID is equal to pageParams.artistID

Screenshots with the important parts in red (i have a sample dataset just to show):

This is the filtering formula:

Ah… I see what you were saying now from a dB perspective. I think the reason I chose to create an Album table was so I could include fields that offered information specific to those albums.

It’s not a player I’m trying to build. More of a music rating/cataloging system that has some unique analytics built in. Weirdly the stuff I thought would be most simple is turning out to be the most complicated. :_)

A system you suggest here is definitely solvable. But the most important factor is to know how do you wish to link between the artists, albums and songs. Sorry, just updated my previous answer with some more details.

This looks very promising! The only problem here is I don’t have the Filtering, Ordering, and Paging options that I see in your screenshot.

Is there something I need to do to have those show up?

oh, is it Airtable? I missed that point.

In this case I have to dive deeper into it. Because those fields might appear only for Firebase connector. I am not sure, though…

I would still stick to a flatter structure but use 3 tables

Collection; Artist
Document: auto assigned ID
Fields: As required. (If you include number of albums then you know the ID for all albums)

Collection; Album
Document: auto assigned ID (Consider using same ID as artist appended with -01, -02 etc indicating album number
Fields: As required, including artist ID as one field (not needed if using the composite ID suggested)

Collection; Song
Document: auto assigned ID (or use composite of Artist -aa-bb where aa is artist album# and bb is track number)
Fields: As required

I believe this would make it simple enough to get at whatever data you wanted. I do something a little similar with some of my data.

1 Like

So if it is Airtable you use for your backend I suggest checking out these posts. Maybe they can help you out:

1 Like

Hey @Mihaly_Toth… the posts linked above were very helpful and I believe have pointed me to the right solution, however something is still not quite working and I was wondering if you could help me diagnose.

I was able to figure out the “filterByFormula” query parameter for Airtable which looks like this:

The specific syntax here is indicating {ArtistID} as the field to filter by and using the existing page parameter “ArtistID” as the condition. This formula is currently yielding zero results, but I don’t think the problem lies with the formula or the syntax; rather it seems it is not recognizing the Artist ID.

If I go into the data collection Test area and use the filterByFormula parameter to select for a static value like the artist name it works perfectly, and you can see the ArtistID field show up in the results:

But when I change the condition to look specifically for that ArtistID I get zero results:

Naturally, the dynamic formula isn’t going to work if it can’t even find a static value, but I can’t figure out why it’s not recognizing the ArtistID when I am pulling it right from the original array.

Any thoughts?

In your data resource artist ID seems to be a list of texts. So changing that to simple text should solve your issue.
So check if in Appgyver and Airtable the ArtistID type is the same.
I don’t know how would you use find by key or similar formulas with airtable queries. But essentially if not changing the type of the artistID to text in Airtable, but having it still as an array (list of texts), you should send the list of texts, from Appgyver app as query parameter. So maybe use:

{ArtistID}=MAP(params.ArtistID, item)

A few brackets to keep in mind:
You can see that in Airtable the
ArtistID: [

  • This “[]” bracket indicates a list or array.
  • The “{}” indicates an object, with its “key”: “value” pairs. But the value can even be “[]” array, or number, or true/false (boolean).
  • And lastly the “()” this is important to check in the formulas, but it is essentially the same as formulas in Microsoft Excel or any spreadsheet.