Created
March 31, 2015 09:39
-
-
Save zosiu/d8e1d1b8266ca56ca0a2 to your computer and use it in GitHub Desktop.
has_many with date_part condition
This file contains 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
# using the awesome squeel gem | |
has_many :shares, dependent: :destroy | |
has_many :stories, through: :shares | |
has_many( | |
:stories_this_month, -> do | |
where do | |
date_part('month', created_at).eq(Date.today.month) & | |
date_part('year', created_at).eq(Date.today.year) | |
end | |
end, | |
through: :shares, | |
source: :story, | |
class_name: 'Story' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment