Created
February 7, 2012 18:42
-
-
Save michaeldhopkins/1761169 to your computer and use it in GitHub Desktop.
why aren't these returning unique?
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
ruby-1.9.2-p290 :056 > Sermon.where("date > ?", Date.today - 365).select(:speaker_id).uniq | |
Sermon Load (0.5ms) SELECT speaker_id FROM "sermons" WHERE (date > '2011-02-07') | |
=> [#<Sermon speaker_id: 1>, #<Sermon speaker_id: 1>, #<Sermon speaker_id: 1>, #<Sermon speaker_id: 1>, #<Sermon speaker_id: 1>] | |
Update: answer: | |
ruby-1.9.2-p290 :070 > Sermon.select(:speaker_id).where("date > ?", Date.today - 365).group(:speaker_id) | |
Sermon Load (0.5ms) SELECT speaker_id FROM "sermons" WHERE (date > '2011-02-07') GROUP BY speaker_id | |
=> [#<Sermon speaker_id: 1>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment