Getting activerecord to write SQL date math

I have a model that has a start_at and length columns. The start_at is a Date column. What I would like to do is find all items that are overdue based on todays date. I’ve got an attr_accessor for due_at that is start_at + length, but that doesn’t seem to carry over to AR.

Any advice help on this one would be greatly appreciated.

Something like this scope will work:

scope :overdue, -> { where('start_at > ?', Time.now + self.length ) }

You need to use a lambda to pass through dynamic properties like Time.now

Hope it helps :slight_smile: