我浏览了许多 SO
和 google
帖子,用于生成 has Many and属许多
关联的连接表迁移,但没有任何效果.
所有解决方案都会生成一个空的迁移文件。
我使用的是 rails 3.2.13
,并且有两个表:security_users
和 assignments
。这些是我尝试过的一些事情:
rails generate migration assignments_security_users
rails generate migration create_assignments_security_users
rails generate migration create_assignments_security_users_join_table
rails g migration create_join_table :products, :categories (following the official documentation)
rails generate migration security_users_assignments security_user:belongs_to assignments:belongs_to
谁能告诉我如何在两个表之间创建连接表迁移吗?
最佳答案
要在命令行中自动填充 create_join_table 命令,它应如下所示:
rails g migration CreateJoinTableProductsSuppliers products suppliers
对于产品模型和供应商模型。 Rails 将创建一个名为“products_suppliers”的表。注意复数形式。
(请注意,生成
命令可以缩短为g
)
关于ruby-on-rails - 生成迁移-创建连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17765249/