Rails 4 query unique by single attribute

前端 未结 6 1295
我寻月下人不归
我寻月下人不归 2021-02-02 10:57

So this is more of an arel question than anything but here\'s what I am trying to do.

I have three objects lets say, called Items



        
6条回答
  •  一整个雨季
    2021-02-02 11:33

    For Mysql, your can use group with ONLY_FULL_GROUP_BY disabled,

    Item.group(:name).to_sql
    => "SELECT `items`.* FROM `items`  GROUP BY name"
    

    See Is there ANY_VALUE capability for mysql 5.6?

提交回复
热议问题