Rails固定装置获取错误的表名 [英] Rails fixtures get table names wrong

查看:65
本文介绍了Rails固定装置获取错误的表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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.

因此,rolespermissions之间的联接表应命名为permissions_roles.

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

这篇关于Rails固定装置获取错误的表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆