title: t.references in Rails migration (n | n relationship)
body: <p>I have three models in my Rails 3 application, <code>DailyData</code> and <code>DailyDataVehicle</code> and <code>Vehicle</code>, a many to many relationship.</p>
  
  <p>I just learned that if you update the model with the associations, that it doesn't update the database, so I am going back and adding those migrations.  I am also lucky enough to confidently think I know the differences between <code>belongs_to</code> and <code>has_many</code>, however, in my migration file, I am not sure that <code>t.references</code> does.<br>
  So I named the migration model <code>AddDailyDataToDailyDataVehicle</code>, and want to add the <code>dailyData_id</code> to the <code>daily_data_vehicles</code> table.  This is a many to many relationship, so I want the <code>id key</code> to be in the relationship table <code>DailyDataVehicles</code>, but I'm not quite sure that <code>t.references</code> will know that.<br>
  Maybe I am slightly mixing up the class associations and the database relationships, and if I am, then please clarify this.<br>
  If <code>t.references</code> is not what I want, do I have to declare the relationship manually with <code>has_many</code>, and if so, what is the syntax for that?</p>
  
  <p>schema file currently:</p>
  
  <pre><code>create_table "daily_data_vehicles", :force =&gt; true do |t|
    t.integer  "vehicle_id"
    t.datetime "created_at", :null =&gt; false
    t.datetime "updated_at", :null =&gt; false
  end
  add_index "daily_data_vehicles", ["vehicle_id"], :name =&gt; "index_daily_data_vehicles_on_vehicle_id"
  </code></pre>
  
  <p>Migration (attempt):</p>
  
  <pre><code>class AddDailyDataToDailyDataVehicle &lt; ActiveRecord::Migration
    def change
      change_table :dailyDataVehicles do |t|
        t.references :dailyData
      end
      add_index :dailyDataVehicles, :dailyData_id
    end
  end
  </code></pre>
  
  <p>What I think the schema file should look like if the migration works correctly:</p>
  
  <pre><code>create_table "daily_data_vehicles", :force =&gt; true do |t|
    t.integer  "vehicle_id"
    t.integer  "dailyData_id"
    t.datetime "created_at", :null =&gt; false
    t.datetime "updated_at", :null =&gt; false
  end
  add_index "daily_data_vehicles", ["vehicle_id"], :name =&gt; "index_daily_data_vehicles_on_vehicle_id"
  add_index "daily_data_vehicles", ["dailyData_id"], :name =&gt; "index_daily_data_vehicles_on_daily_data_id"
  </code></pre>
  
  <p>with the difference being <code>t.integer  "dailyData_id"</code> and <code>add_index "daily_data_vehicles", ["dailyData_id"], :name =&gt; "index_daily_data_vehicles_on_daily_data_id"</code></p>