`uniq` in has-many based relations is order-dependent #8270

RKushnir opened this Issue Nov 19, 2012 · 1 comment


None yet

2 participants


I believe the following behaviour is inconsistent. Here's the code:

class Post < ActiveRecord::Base
  has_many :comments

post.comments.where(author: 'bob').uniq produces a valid SQL-query with DISTINCT, whereas post.comments.uniq.where(author: 'bob') says NoMethodError: undefined method 'where' for #<Array:0x...>.
Also post.comments.scoped.uniq.where(author: 'bob') works as the former case.


This is how things work. If you call uniq, it converts to an array and then uniqs it. Arrays do not have a where method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment