Question

I want to ensure that only Movies with a watched date are brought back and ordered by that value in ascending order.

I think I'm fairly close with the following:

default_scope :conditions => { :watched_date => not null },
              :order => 'watched_date ASC'

But I don't know how to add a condition for a non-null date.

Was it helpful?

Solution

Does it work if you change the conditions to this?:

:conditions => 'watched_date IS NOT NULL'

You might want to include the table name incase this is used in joins like so:

:conditions => 'movies.watched_date IS NOT NULL'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top