0

I'm logging all impressions of a certain page, by saving each visit as a record in Impression.

Impression saves the user_id if the visitor is logged in, hence some records have no user_id saved.

When querying the log to display number of visits I want to exclude the admins of the site.

The following is one way to exclude the admins, but it doesn't include records with no user_id atribute:

Impression.where("user_id NOT IN (?)", [1,2])

How can I, in Rails 3.2, do a query which excludes records with certain (multiple) attribute values?

4

2 回答 2

2

尝试这个:

Impression.where("user_id is not null and user_id NOT IN (?)", [1,2])
于 2013-09-27T14:42:17.263 回答
1

Impression.where("user_id is null OR user_id NOT IN (?)", [1,2])

于 2013-09-27T17:49:59.517 回答