I have the following piece of AR/SQL code returning the following value:
Post.joins(:comments).uniq.count # => 20
When I refine it as below, I get the reduced value I would expect:
Post.joins(:comments).uniq.where('.user_id = ?', user.id).count # => 9
So when I run the same code but with the match negated, I would expect the to get the opposite bunch of records - ie a count of 11. But instead I get this:
Post.joins(:comments).uniq.where('comments.user_id != ?', user.id).count # => 20
I want to say, basically "Find all posts with comments where the comment was made by someone other than ."
Have I misunderstood how negation behaves in SQL?
I should specify that I'm using Rails 3.2.18, which doesn't seem to allow the where.not() syntax I found in the Rails guide (it raises ArgumentError: wrong number of arguments (0 for 1)).
Aucun commentaire:
Enregistrer un commentaire