Created
September 5, 2025 00:23
-
-
Save matt17r/91bc7ddb2ab2a18f40866e3b40319ef0 to your computer and use it in GitHub Desktop.
Time comparison... greater than == more recent than π€¦ββοΈ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # I found this confusing to read... Active ones are ones that were read less than seven days ago so why is this a greater than symbol? | |
| scope :active, -> { where("read_at IS NULL OR read_at > ?", 7.days.ago) } | |
| # Of course! A date that is greater than another date is more recent than the other date π€¦ββοΈ | |
| scope :active, -> { where("read_at IS NULL OR read_at > ?", 7.days.ago) } # '>' == 'more recent than' | |
| # But I think we can do better than [just] a comment (plus I already had an unread scope, why aren't I using it here???) | |
| scope :unread, -> { where(read_at: nil) } | |
| scope :read_within_past, ->(period) { where("read_at > ?", period.ago) } # '>' == 'more recent than' | |
| scope :active, -> { unread.or(read_within_past(7.days)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment