I've tried a bunch of variations of this migration file:
我尝试了一些此迁移文件的变体:
class CombineTags < ActiveRecord::Migration
def change
create_join_table :habits, :valuations, :quantifieds, :goals do |t|
t.timestamps null: false
end
t.index :habits, [:habit_id, :tag_list], :valuations, [:valuation_id, :tag_list], :quantifieds, [:quantified_id, :tag_list] :goals, [:goal_id, :tag_list]
end
end
but I keep getting this error upon running rake db:migrate
:
但是在运行rake db:migrate时我一直收到这个错误:
Anthony-Gallis-MacBook-Pro:pecoce galli01anthony$ rake db:migrate
== 20150506172844 CombineTags: migrating ======================================
-- create_join_table(:habits, :valuations, :quantifieds, :goals)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (4 for 2..3)/Users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/activerecord-4.2.0.rc3/lib/active_record/connection_adapters/abstract/schema_statements.rb:248:in `create_join_table'
This is just one step in trying to achieve my ultimate goal: How to use multiple models for tag_cloud?
这只是尝试实现我的最终目标的一步:如何为tag_cloud使用多个模型?
1 个解决方案
#1
The create_join_table accept only 3 args (last of them is optionals, look at link). So, you can't create join table for 3 tables use this method.
create_join_table只接受3个args(最后一个是选项,查看链接)。因此,您无法使用此方法为3个表创建连接表。
In you case you should create join table use create_table and specify correspond reference fields.
在您的情况下,您应该创建连接表使用create_table并指定对应的引用字段。
#1
The create_join_table accept only 3 args (last of them is optionals, look at link). So, you can't create join table for 3 tables use this method.
create_join_table只接受3个args(最后一个是选项,查看链接)。因此,您无法使用此方法为3个表创建连接表。
In you case you should create join table use create_table and specify correspond reference fields.
在您的情况下,您应该创建连接表使用create_table并指定对应的引用字段。