Skip to content
Discussion options

You must be logged in to vote

Naively, all the data are there so I suppose one could just iterate through the Vec<(Page, Book)> and build one or more BookWithPages structs that way, but is there a more elegant / idiomatic way to do it?

That's what needs to be done. There is no way to skip this work. Diesel doesn't currently provide any API for this, so you need to roll your own implementation.

To do this you would need roughly the following:

  1. Create a HashMap<i32, (Book, Vec<Page>)>
  2. Iterate over all (Book, Page) pairs and:
    • Check if the book with the given id already exists in the hashmap, if not insert it with an empty page vector
    • Push the page to the page vector
  3. Iterate again over the HashMap to create the BookW…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@grifferz
Comment options

Answer selected by grifferz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants