This is a great book! I’m always on the lookout for new beta versions to be published so I can read the new chapters that are released.

I don’t think PragProg allows forums anymore on their site (only errata) and I have a question about the latest chapter 12. First, I really appreciate that chapter since many times books don’t get into higher level application design topics (maybe to avoid “flame wars”)

Question I have is about the good “general rule” advice to put all pure functions manipulating queries, changesets, and multis into their associated schema modules and put all the impure code into context modules. Right now I put all changeset code in the schema modules but usually leave the multi (and query) code in the context module… generally since my multis and queries are affecting multiple DB tables/schemas so they don’t really belong in any specific schema module. Are you recommending maybe using Multi.merge extensively to build up the whole multi in the context module calling functions in the schema modules… or something else?

I looked at the sample code that comes with the book and can’t find much use of multi (yet). Are there any large/decent scale OSS projects I can study that follow the recommended pattern… especially as it relates to Multi or query use defined in schema modules?

Chapter 12 was a difficult chapter to write, balancing our experiences writing Ecto applications while still maintaining that there is no right or wrong and that there may be other equally valid ways of organizing applications. Where Multi fits best was something we discussed while writing the chapter and it seems like somewhere during the discussions some things were missed.

After discussing this again we are amending this part of the chapter and adding a paragraph that clarifies that we believe multi fits better in context modules than schema modules. The reason being, while multi is a pure data structure like changesets, with multi you usually compose functions from multiple schemas and with changesets you compose functions within a single schema. Since multi is working with multiple schemas it fits better on a higher level inside a context.

Thank you for bringing this up and helping us improve the book during the beta!

It did work much better this time. Although this time I got warnings like the ones below:
==> music_db
Compiling 14 files (.ex)
warning: invalid association notes in schema MusicDB.Artist: associated schema MusicDB.Note does not have field artist_id
lib/music_db/artist.ex:9: MusicDB.Artist (module)