我想创建以下模型:
create_table "item_groups", force: true do |t|
t.string "name", null: false
t.integer "locale_id", null: false
t.boolean "translated", default: false, null: false
end
如何添加一个多列索引,该索引仅索引翻译 = true (Postgres)。我想它看起来有点像这样:
add_index "item_groups", ["translated", "locale_id"], name: "item_groups_translated_locale_id", where: "translated = true", using: :btree
更新
我正在使用 Rails 4。上面的语法是否正确?
更新 2
我将语法更改为
add_index "item_groups", ["translated", "locale_id"], name: "item_groups_translated_locale_id", where: "(translated IS TRUE)", using: :btree
有关 Edgars Jekabsons 答案的更多信息,请访问https://coderwall.com/p/9hxejg