Skip to content

Instantly share code, notes, and snippets.

@nicolasiensen
Created August 20, 2012 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolasiensen/3406690 to your computer and use it in GitHub Desktop.
Save nicolasiensen/3406690 to your computer and use it in GitHub Desktop.
User.joins(:pokes).
select("users.*, (
SELECT COUNT(p.*) FROM pokes p
WHERE p.user_id = users.id
AND p.campaign_id = #{self.id}
) as pokes_count").
where(["pokes.campaign_id = ?", self.id]).uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment