Created
August 24, 2011 15:34
-
-
Save robertomiranda/1168322 to your computer and use it in GitHub Desktop.
Find tournament's players by categories
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
class Tournament < ActiveRecord::Base | |
#SELECT "players".* | |
#FROM "players" | |
#WHERE "players"."id" IN ( | |
#SELECT "players"."id" | |
#FROM "players" | |
#INNER JOIN "pairs" | |
#ON ("pairs"."player_id" = "players"."id" OR "pairs"."partner_id" = "players"."id") AND "pairs"."tournament_id" = 4) | |
def player | |
players = Player.arel_table | |
pairs = Pair.arel_table | |
condition = (pairs[:player_id].eq(player[:id]).or(pairs[:partner_id].eq(player[:id]))).and(pairs[:tournament_id].eq(self.id)) | |
Player.where(:id => Player.select(players[:id]).joins(:pairs).on(condition)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment