Rails 3.0.4で複合一意制約を定義する方法は二通りあるようです。 1.ActiveRecordでモデルに一意制約を定義する 2.RDBMSで一意索引を作る 通常は両方実装するものと思われます。 次のようなモデルで確認します。 class CreateMultiples < ActiveRecord::Migration def self.up create_table :multiples do |t| t.string :key1 t.string :key2 t.string :key3 t.string :value t.timestamps end end def self.down drop_table :multiples end end まず1.の場合ですが、Stack Overflowにありました。 In Rails 2, I would have written:
![Railsのモデルに複合一意制約を定義する方法、そしてうっかりハマる - 杉風呂2.0 - A Lifelog -](https://cdn-ak-scissors.b.st-hatena.com/image/square/192a70db0b8cbba1b5747ce54daa49640964a9cc/height=288;version=1;width=512/https%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fs%2Fsuginoy%2F20110508%2F20110508002206.jpg)