Rails fixtures get table names wrong

萝らか妹 提交于 2019-12-08 20:10:52

By convention, the join table name between two tables is named alphabetically.

So, the join table between roles and permissions should be named permissions_roles.

You need to create the table permissions_roles instead of roles_permissions, or set the table in the options(:join_table):

has_and_belongs_to_many :roles, join_table: "roles_permissions"

#has_and_belongs_to_many:

Unless the join table is explicitly specified as an option, it is guessed using the lexical order of the class names. So a join between Developer and Project will give the default join table name of “developers_projects” because “D” precedes “P” alphabetically

Read more here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!