wolfiton
Naming convention for associations using generators
Hi everyone,
What naming convention would you use to create associations when you use generators like this:
mix phx.gen.context Blog Post posts title body
Then you have a many-to-many with Tags
mix phx.gen.context Blog Tag tags name description
mix ecto.gen.migration create_tags_posts for the join through
Because the docs confuse me a little on best practices and clarity Ecto Association Guide – Ecto v2.2.11 especially this part EctoAssoc.Post
Do you rename the schema in TagsPosts or how do you name this relationship?
Thanks
Most Liked
kokolegorille
I use plural form in alphabetical order, but it’s just by convention… You can use whatever name You want.
So in this case, I would use posts_tags.
kokolegorille
Following my convention, I would use
mix ecto.gen.migration create_posts_tags
kokolegorille
Sometime it makes sense to use more descriptive name…
For example, User m2m Role with a membership join table. Membership is much more descriptive than roles_users.
Popular in Chat/Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








