Answer the question
In order to leave comments, you need to log in
How to write uniqueness in database on rails?
We have such a table in schema.rb
create_table "menus_products", force: :cascade do |t|
t.bigint "menu_id"
t.bigint "product_id"
t.index ["menu_id"], name: "index_menus_products_on_menu_id"
t.index ["product_id"], name: "index_menus_products_on_product_id"
end
Answer the question
In order to leave comments, you need to log in
Create a composite unique index
add_index :menus_products, %i[menu_id product_id], unique: true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question