Ruby-on-Rails: Selecting distinct values from the model

前端 未结 4 1400
攒了一身酷
攒了一身酷 2020-12-16 13:12

The docs: http://guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields

Clearly state that:

query = Client.select(:name).distin         


        
4条回答
  •  自闭症患者
    2020-12-16 13:27

    If you do not want ActiveRecord::Relations returned, just an array of the names as strings, then use:

    Client.distinct.pluck(:name)
    

    To get an ordered result set:

    Client.order(:name).distinct.pluck(:name)
    

提交回复
热议问题