create_join_table只能带2-3个参数吗?

时间:2015-05-06 18:32:34

标签: ruby-on-rails ruby migration

我尝试过这个迁移文件的一系列变体:

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

但是我在运行rake db:migrate

时一直收到此错误

&#13;
&#13;
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'
&#13;
&#13;
&#13;

这只是尝试实现我的最终目标的一步:How to use multiple models for tag_cloud?

1 个答案:

答案 0 :(得分:1)

create_join_table只接受3个args(最后一个是选项,查看链接)。因此,您无法使用此方法为3个表创建连接表。

在这种情况下,您应该创建连接表使用create_table并指定相应的参考字段。