SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Something like this scope will work:
    Code ruby:
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •