AnthonyGalli.com
AnthonyGalli.com

Reputation: 2866

Can create_join_table only take 2-3 arguments?

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:

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?

Upvotes: 0

Views: 44

Answers (1)

marilyne.christiansen
marilyne.christiansen

Reputation: 176

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.

In you case you should create join table use create_table and specify correspond reference fields.

Upvotes: 1

Related Questions