Creating a many to many relationship in rails 4 -


how can create relationship table in migration class both references used in unique index?

class creatediagnostichypotheses < activerecord::migration   def change     create_table :diagnostic_hypotheses, :id => false |t|       t.references :accident_indication, index: true       t.references :forms, index: true        t.timestamps null: false     end      add_foreign_key :diagnostic_hypotheses, :accident_indications     add_foreign_key :diagnostic_hypotheses, :forms, column: :diagnostic_hypothesis_id   end end 

when run rake db:migrate tries create separate indexes. how can create 1 unique index both :accident_indication , :forms references?

you can create unique composite index:

class creatediagnostichypotheses < activerecord::migration   def change     create_table :diagnostic_hypotheses, :id => false |t|       t.references :accident_indication       t.references :forms        t.timestamps null: false     end      add_index :diagnostic_hypotheses, [:accident_indication_id, :forms_id], :unique => true      add_foreign_key :diagnostic_hypotheses, :accident_indications     add_foreign_key :diagnostic_hypotheses, :forms, column: :diagnostic_hypothesis_id   end end 

i didn't try myself, however, think you've got idea.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -