I am looking to render some templates and pass in nested objects. I havent seen many examples of this. It compiles, but Im looking more for ideas on how idiomatic the approach is.
For example, say the following case classes are built from a Slick database query
case class ThemedListOfAlbums(
themeName: String,
description: String,
albums: List[Album]
)
case class Album(
name: String,
artist: String,
imageUrl: String
songs: List[Song]
)
case class Song(
name: String,
imageUrl: String,
description: String
)
is it then just as simple as passing the complex object?:
@(user: User, catalogs: List[ThemedListOfAlbums])
//stuff
<ul>
@for(c <- catalogs) {
//?? want to render a partial for each catalog with a list of album images
//with song names on them
}
Is there a limit to levels of nesting before I need to rethink what I am trying to render completely?
a link to an example would be helpful if this qualifies as a "do your homework" question. cant seem to find any pertinent info
Provided your Slick query properly populates
ThemedListOfAlbums.albums
andAlbum.songs
then I don't see why this wouldn't workI'd be more interested to see the kinds of queries you're using as this kind of approach can very quickly lead to a large amount of database queries for a single page
For example, one query could easily get a list of
Album
for the root object, but if eachAlbum
then makes a database call for a list of relatedSongs
then you're going to have a huge amount of database requests, especially considering your view contains a list ofThemedListOfAlbums