我有以下迁移:
create_table :product_attr_vals do |t|
t.references :product, foreign_key: true
t.references :attr_val, foreign_key: true
t.timestamps
end
如何为t.references
和
答案 0 :(得分:1)
尝试以下方法:
create_table :product_attr_vals do |t|
t.references :product, foreign_key: true
t.references :attr_val, foreign_key: true
t.timestamps
end
# Add this line
add_index :product_attr_vals, [:product_id, : attr_val_id], unique: true