Rails 4 query unique by single attribute

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

    I can't comment on posts yet, so, putting this as another answer for the question.

    In case of someone still searches for this, @BananaNeil's answer is correct. However, putting distinct in select didn't work for me (Rails 5.2.2). Separating these two did fix my problem.

    klass.where(
      # Your query or whatever
    ).distinct.select('on (attribute) *')
    

提交回复
热议问题