wolfiton

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 https://hexdocs.pm/ecto/2.2.11/associations.html especially this part EctoAssoc.Post

Do you rename the schema in TagsPosts or how do you name this relationship?

Thanks

Most Liked

kokolegorille

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

kokolegorille

Following my convention, I would use

mix ecto.gen.migration create_posts_tags
kokolegorille

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.

Where Next?

Popular in Chat/Questions Top

loganhelms
A while back, I read a great book by Luis Atencio titled, Functional Programming in JavaScript. In section 7.3, he discusses memoization ...
New
eliottramirez
Hello, I’m trying to learn Phoenix but I constantly find difficult understanding how the framework works, and I think part of this is th...
New
maqbool
what books/Resources do you recommend to learn about distributed system(theory)?
New
ggwc82
Looking to get started with FP and Elixir coming mainly from an OOP Rails and PHP background. My first question is, whats the best cours...
New
jslearner
Will learning Erlang really help in being a better Phoenix or Elixir developer or is it a waste of time?
New
stevensonmt
I’d like to provide my review of the Elixir Course module from Groxio. I have some criticisms but I’d like to start with the positives. ...
New
imanuelgittens
Hey all! Just joined the forum and I’m very excited to learn the language. I just finished reading the documentation and I was wondering ...
New
Nopp
Hello there, i have a lot to read and to learn, but are there some books, that are focussing on how i “should” plan the architecture of ...
New
pdgonzalez872
Do we have a list of academic/research papers: about Elixir/Erlang? that use Elixir/Erlang? about the Beam? If so, could you please po...
New
younes-alouani
I'm studying Phoenix Framework but I want to understand basics first. Which book/mooc explains better the Design of Network-based Softwar...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement