ruby on rails - Why doesn't this ActiveRecord SQL != query do the opposite of the equivalent = query? -
i have following piece of ar/sql code returning following value:
post.joins(:comments).uniq.count # => 20
when refine below, reduced value expect:
post.joins(:comments).uniq.where('comments.user_id = ?', user.id).count # => 9
so when run same code match negated, expect opposite bunch of records - ie count of 11. instead this:
post.joins(:comments).uniq.where('comments.user_id != ?', user.id).count # => 20
i want say, "find posts comments comment made other ."
have misunderstood how negation behaves in sql?
i should specify i'm using rails 3.2.18, doesn't seem allow where.not()
syntax found in rails guide (it raises argumenterror: wrong number of arguments (0 1)).
the second query responding question: find posts @ least 1 comment not made ... looks user has commented in 9 posts. else has made comment in posts.
Comments
Post a Comment