Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtaining ActiveRecords if NOT nil

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]
like image 651
scott Avatar asked Jan 29 '26 08:01

scott


1 Answers

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"]
like image 171
Vincent Robert Avatar answered Jan 30 '26 20:01

Vincent Robert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!