John
John

Reputation: 6612

Check date unless blank in model

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

Answers (1)

KL-7
KL-7

Reputation: 47608

projects.where(...).where('end_date IS NULL OR end_date >= ?', Time.now)

Upvotes: 2

Related Questions