Reputation: 6612
In a model I have a query like this to get active projects:
self.projects.where('start_date <= ?', Time.now).where('end_date >= ?', Time.now)
Now it can be possible to have an empty end_date. How can I make the second where optional so it only applies to filled in end_dates?
Upvotes: 0
Views: 112
Reputation: 47608
projects.where(...).where('end_date IS NULL OR end_date >= ?', Time.now)
Upvotes: 2