Rails固定装置获取错误的表名 [英] Rails fixtures get table names wrong
问题描述
我有一个roles
表,一个permissions
表,并以多对多关系将它们连接到一个roles_permissions
表.
I have a roles
table, a permissions
table, and to join them in a many-to-many relationship a roles_permissions
table.
在roles.yml
文件中,我有这个:
admin:
name: admin
permissions: create_user, edit_user, view_all_users
在permissions.yml
中,我有:
create_user:
name: create_user
description: Create a new user
edit_user:
name: edit_user
description: Edit any user details
view_all_users:
name: view_all_users
description: View all users
现在rake test
给了我说no such table: permissions_roles: DELETE FROM "permissions_roles"
当我注释掉roles.yml
中指定管理员权限的行时,错误消失了.
When I comment out the line in roles.yml
that specifies the admin permissions then the errors go away.
当固定装置实际命名为roles_permissions
It looks like the fixtures are assuming the joining table is named permissions_roles
when it's actually named roles_permissions
如何告诉它正确的表名?
How do I tell it the right table name?
推荐答案
按照惯例,两个表之间的联接表名称按字母顺序命名.
By convention, the join table name between two tables is named alphabetically.
因此,roles
和permissions
之间的联接表应命名为permissions_roles
.
So, the join table between roles
and permissions
should be named permissions_roles
.
这篇关于Rails固定装置获取错误的表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!