Rails 4 query unique by single attribute

前端 未结 6 1294
我寻月下人不归
我寻月下人不归 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:29

    If you want to get the entire model back, but still maintain uniqueness, you can use this:

    Item.select('distinct on (name) *')
    

    I've only tested this with a Postgres database. It may or may not work with mysql.

提交回复
热议问题