Adding an index on a boolean field

后端 未结 2 1716
自闭症患者
自闭症患者 2020-12-30 22:46

I have a Rails model with a boolean field that I search on (I use a scope that finds all instances where the field is set to true). I\'m using Postgres.

My instinct

2条回答
  •  没有蜡笔的小新
    2020-12-30 23:03

    To create the partial index in a Rails migration, you would do this. In this example, the model is Product and the column is featured.

    class AddFeaturedOnProducts < ActiveRecord::Migration
      def change
        add_index(:products, :featured, where: "featured")
      end
    end
    

提交回复
热议问题