I forgot to mention, whenever I see Ecto schema structs bubbling up to the views, I want to throw up.
How else would you do it? It would seem to me (admittedly, naively) that anything else would introduce an unnecessary extra layer between the context and the view. What am I missing?
If your application is a simple CRUD app, then yes, bubbling up Ecto schema structs to the vies is sufficient.
Because the context is the “public API” for the rest of your application to use. You can have as many layers below the context as you want, often purely functional, composable, and testable.
My understanding of contexts (from the docs) is that they are intended to "...encapsulate data access and data validation." They're intended to be the layer of your application that talks to the database. Do you have a different approach?
Re: the sibling comment referring to queries, nothing you’re doing in the article prevents that.
Ecto’s changesets are often an unfamiliar concept, so I wonder if that’s where some confusion is coming from.
However, what you say about having different changesets for validation seems to make a ton of sense to me and has given me some ideas. Thanks.
I don't think this is a terrible idea but I like to draw boundaries and say "It's ok to reach one level deep from any point in the context tree".
ie App.Chat.send_message/2 is cool, but MyApp.Chat.Messages.send_message/2.