JM (Jason Meridth)

JM (Jason Meridth)

Learn, Converse, Share

03 Feb 2013

Has And Belongs To Many Join Table Name Must Be In Alphabetical Order

TL;DR

Read this from the Rails Guides

Today I created an explicit join table between two models because each had has_and_belongs_to_many, as I’ve done many time before. Except, this time, when I tried to render one of my views, it said it couldn’t find a join table.

Example:

I created users_roles and the view error stated it was looking for roles_users.

Incorrect:

users_roles

Correct:

roles_users

My first inclination was the fact that it was looking for it in alphabetical order. Sure enough, the Rails Guide Documentation states that Rails developers do need to explicitly create their join tables but they have to be in lexical order (alphabetical).

Tags