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

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.

1 Like

So you have to create a new Schema with changeset that matches this migration or the post and tag schema should take care of it using the many-to-many relationship on them?

Following my convention, I would use

mix ecto.gen.migration create_posts_tags
1 Like

Thanks @kokolegorille now i think I get it because i seen code using weird convention to define this relationship and odd naming.

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.

1 Like

Sometimes but not in general, someone new can get easily confused by the naming, especially if he/she has just joined the project