Rails ActiveRecord query where column date plus days from another column are in a given date range

Viewed 23

I want to find documents where the due date is in a given date range. However, the due data is not a property of the document. It does have a creation date and a number of days till it is due.

So I cannot do this:

Document.where(due_date: date_start..date_end)

This (wrong code) is the intention:

Document.where(created_on + due_interval.days: date_start..date_end)

How would this query look like using Ruby on Rails' ActiveRecord ORM? Assume two dates given: date_start and date_end and the relevant properties on the model are created_on and due_interval.

0 Answers
Related