msyavuz
Hello, i am a newbie in both phoenix and elixir and its been a blast so far. I have a question about ecto schemas and phoenix contexts.
Suppose i have two tables called clubs and club_members. While generating a new schema with phx.gen.schema
-
Should i create the club schema under club context ?
-
Or should i create club schema without context and put member schema under club context?
First approach results in module name being Club.Club but directory structure seems better. While module naming in second approach seems better but club schema sits outside club directory.
I guess what i am asking is which one of these is better?
/001 club/ member.ex
/002 club.ex
/001 club/ member.ex
/001 club/ club.ex
Trending in Questions
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
Hi all!
I know that quite a few people use Phoenix LiveView but it is hard to get a more up-to-date list of folks/companies using it. I ...
New
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Hey, I know this has been discussed ad nauseum, but I couldn’t find a definitive answer or at least some consensus around this, so let me...
New
I don’t suppose you can lazy load a library depending on runtime data? For example if it’s a certain user they can lazy load ‘library A’ ...
New
Hey everyone, I have been building a lightweight Phoenix backend aimed at backing up and synchronizing user profiles across mobile device...
New
Other Trending Topics
For us who are worried about our DNA I’ve recently released bam 0.1.0, a library for SAM and BAM alignment files.
BAM is a file format ...
New
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New
Hi everyone :waving_hand:
I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #code-sync
- #exunit
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #ai
- #authentication
- #elixirconf-us
- #umbrella
- #full-time-contract
- #blog-post
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-eu
- #distillery
- #security
- #processes
- #api
- #forms
- #hex











Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachallaun
The most common way to solve this would be to call the context
clubs, so you would haveClubs.ClubandClubs.Member.sodapopcan
Generally if you are using contexts as a boundary, then you put all the schemas belonging to a context under it.
Also by convention, if there isn’t a good unique name for a context (which there often isn’t) then it’s the pluralized version of its primary schema. You could just call your context
Clubif you want, but this can become confusing and it also makes it impossible to alias the schema within the context as they will have the same name. So the “normal” thing to do is this:This way the directory structure mimics the module structure. Some people like to put the context file in the context directory, which is fine, whatever floats your boat!
Technically, though, you are free to do whatever you want! The generators push us towards certain conventions, but otherwise Phoenix doesn’t impose any conventions on us.
msyavuz
Thank you for the explanation!