views:

68

answers:

2

I would like to be able to gather all records in a table where the user_id is not null. This is what I have but it doesn't seem to be working (even though I've had it working in a seperate project):

named_scope :all_registered, :conditions => ["user_id != ?", nil]
+5  A: 

SQL has a specific operator to check for NULL: IS NULL and IS NOT NULL

named_scope :all_registered, :conditions => ["user_id IS NOT NULL"]
Vincent Robert
+1  A: 

This should work:

named_scope :all_registered, :conditions => "user_id IS NOT NULL"
Tomas Markauskas