This felt wrong to me for a long time, but I’ve come around. It’s fine. Code that gets reused or needs further validation can go in contexts.
Reposted from
Owen Bickford
Years ago, I heard a hot take on a podcast that stuck with me and I've been taking it more seriously in the past few months. Something along the lines of "just write the query in the controller/LV and move on with your life." IIRC, this was a classic Chris Keathley hot take.
Comments
I think Contexts are balanced in what they are supposed to be, not forcing you into a specific concept but allowing you to organize your code better.
Learning Django for instance is way more complicated than Phoenix (if we discard the argument of Functional Language vs Imperative).
I love coding and the craft but I also prefer rules because I know down the road it will byte you in the arse. BUT there is a balance to achieve between expressiveness and complexity.
The more you increase prescription the more the barrier of entry is.
2. Break out what’s prudent into a base query within a context (like handling tenancy).
3. Pipe that base query into what your view needs.
It’s that shrimple 🦐