ActiveRecord select except columns

后端 未结 4 790
栀梦
栀梦 2020-12-15 06:54

Is there a way I can specify to select ALL columns in ActiveRecord except just a few. For example, for a User, I don\'t want to select their password hash or their email. Is

4条回答
  •  猫巷女王i
    2020-12-15 07:29

    write a scope like

    def select_without columns
      select(column_names - columns.map(&:to_s))
    end
    

提交回复
热议问题