create_join_table 可以只接受 2-3 个参数吗?
Can create_join_table only take 2-3 arguments?
我尝试了这个 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
:
时不断收到此错误
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'
这只是我实现最终目标的第一步:
create_join_table 只接受 3 个参数(最后一个是可选参数,请看 link)。因此,您不能使用此方法为 3 table 创建连接 table。
在这种情况下,您应该使用 create_table 创建连接 table 并指定相应的参考字段。
我尝试了这个 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
:
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'
这只是我实现最终目标的第一步:
create_join_table 只接受 3 个参数(最后一个是可选参数,请看 link)。因此,您不能使用此方法为 3 table 创建连接 table。
在这种情况下,您应该使用 create_table 创建连接 table 并指定相应的参考字段。